MdiList Restore Minimized form

jshurpin

Member
Joined
Dec 15, 2005
Messages
8
Programming Experience
10+
Hi.
I have an MDI (parent) form containing a Menu, which has a "Windows" item with MdiList set to True. It works fine, showing all the open child forms, etc.
If a child form happens to be minimized when you select it in the "Windows" sub-menu, it becomes the "Active" form, but it remains minimized.
Is there a way to trap when ActiveMdiChild changes, (or some other way), so that the newly activated form can be "Restored" as it is selected ?

Thanks,
Joe Shurpin
 
MDIChildActivate event of the MDI parent form should occur some time around when ActiveMDIChild property changes.
 
Thanks, I'm basically there. I put the following in my program:

Private Sub MainMenu_MdiChildActivate(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
Dim xFrm As Form = Me.ActiveMdiChild
If Not xFrm Is Nothing Then
xFrm.WindowState = FormWindowState.Normal
End If
End Sub

If you click on a minimized form in the "Windows" sub-menu, the form will become active and be in "Normal" (i.e. not minimized) state.

However, since there must always be one active child, this makes it impossible to minimize all the child forms (except when there is only one - see next paragraph). When you minimize the last open form, another (minimized) one will be restored to normal.

Also, if there is only one child form open and you minimize it, selecting it in the "Windows" sub-menu does not restore it to normal state. This is presumably because the "only form" was active already so that the "activate" event doesn't fire.

I can live with this, but it would be nice to be able to detect whether the form becoming active is the result of it being selected in the "Windows" sub-menu, or because of another reason. Also, detecting the selection in the "Windows" sub-menu would work for a single minimized child form.

Thanks again,

Joe
 
There is another way around that will get exactly the same effect as the above code, use the Activated event in the MDI child form, whenever a mdi child form is activated it will set itselfs window state to normal.
VB.NET:
Private Sub MDIForm_Activated(sender, e) Handles MyBase.Activated
  Me.WindowState = FormWindowState.Normal
End Sub

If you want custom behaviour to the 'mdi windows' menu, you can make the menulist yourself.
 
I am getting closer. The following code improves matters somewhat. It allows you to minimize all the forms, since the state is only set to normal if the MdiChild list popub/sub-menu is open. But it won't set to normal a form that is the active child but is minimized. In actual practice this shouldn't be much of an issue.

VB.NET:
Dim OpenForms As Boolean = False
 
Private Sub QHMain_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
     Dim xFrm As Form = Me.ActiveMdiChild
     If Not xFrm Is Nothing Then
          If OpenForms Then xFrm.WindowState = FormWindowState.Normal
     End If
     OpenForms = False
End Sub
 
Private Sub TheMdiList_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles TheMdiList.Popup
     OpenForms = True
End Sub
There is also the matter of the OpenForms flag remaining set to True if the popup closes because you clicked somewhere on the form not on a menu selection. While this can lead to "unusual" behaviour (e.g. a single click will open the minimized form rather that the usual double click), it should not be a real issue in practice. In a word, I'll probably leave it as is.

Thanks again,
Joe
 
Back
Top