Question

The Task

I manage a big application that is based on a main MDI form. All other forms are children of this MDI form or dialogs of the children. As it is a big application, opening and closing the child windows causes some flickering in the whole application. I was tasked to remove this flickering effect as it looks untidy. My main thought was to make all child windows inherit a "Master" form that would deal with all the commonplace functionality that all forms had to include. From here, I could fix any problems in this one central point which would make managing the application much easier.

The Problem

To resolve the flickering, I found a solution on the web that solves my problem. However, not long ago I found that this also introduced a new problem on the "Master" form where if any form had its "ShowIcon" property to false, the "Master" form would force it to be the default visual studio form icon. I narrowed this down to the anti-flicker solution I found on the web (below).

Private imActive As Boolean = False
Private defaultEX As Integer = -1
Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        Dim cp As CreateParams = MyBase.CreateParams
        If defaultEX = -1 Then
            defaultEX = cp.ExStyle
        End If
        If DesignMode = False and imActive = False Then
            cp.ExStyle = cp.ExStyle Or &H2000000
        Else
            cp.ExStyle = defaultEX
        End If
        Return cp
    End Get
End Property

If I comment this out, it works fine but the flickering is unbearable.

The Question

I would like to know if there is an alternative to the current solution or if there is something I can set within the "cp" variable that would remove the icon?

The Example

I have created a quick application that emulates part of my problem. I could not replicate the flickering as this is down to the application being big. However, in this test project, I have replicated a form that inherits a "Master" form with the above code on. This then disallows the icon to be removed (even in the designer). dropbox.com/s/mg9fyfoshakc69z/TestProject.zip

For this replication, I did not need to include the MDI parent, I have however got an inherited form (MasterForm) and a form that inherits it (Form1). MasterForm has code that overrides the CreateParams property. This effects Form1 in such a way that when the toggle for ShowIcon for the window is set to false, it shows the default VB window icon instead of removing it.

Était-ce utile?

La solution

Having run the demo application the only difference I can see is the ImActive flag.

Modifying a similar flag added to your test project set had various results for me, I would recommend changing where this is set until you get the desired result.

Set to false after the form is shown seemed to work best.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top