Question Repeating Events

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
In several forms I use an event handler for the resize event. When a particular form is minimized, I need to do a quick clean up of related forms, also displayed, to clear the screen. When the same form is then maximized, I run a process to restore those related forms. I've noticed that 'some' of the (maximize) resize events get called twice (sequentially) by the system's "external code" and others do not. This runs my restoration code twice and is a bit distracting for the user. The various forms are almost identical in their properties and code layout and yet some get maximized twice. Are there any insights out there on what causes these resize events to pop up sequentially like that and is there any way to prevent it?

VB.NET:
Private Sub Me_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

        [COLOR="Green"]'  "Me" is a mostly transparent form overlying the main form "Frm"[/COLOR]

        If Me.WindowState <> FormWindowState.Minimized And Frm IsNot Nothing Then
            Frm.Show()      [COLOR="green"]'   This is the main underlying form.[/COLOR]
            RefreshPages()  [COLOR="green"]'   This is my restoration process for other related forms.[/COLOR]
        End If
    End Sub
 

Attachments

  • Page0.jpg
    Page0.jpg
    16.3 KB · Views: 34
Why don't you use the Owner forms feature? Makes owned forms minimize/restore/close and overlay with the owner automatically.

Of curiosity I also checked Resize event when maximizing a form, and it does happen twice, but only once for WindowState Maximized. If you need to know that a regular resize event is not followed by a maximized/minimize/restore resize event you can use the ResizeBegin and ResizeEnd events, they don't occur for min/max/restore.
 
I seem to have problems controling the "z-order" of forms when I use the "Owner" and "Owned" forms properties. Invariably, the form I need on top is hidden below all other forms and the ones I need in between are in the wrong order when the screen is restored. Of course I can use the "Topmost" property for the top form but that doesn't help with the intermediate forms and sits on top of any other apps that get restored without minimizing my app.
 
Back
Top