k3n51mm
asked on
MDI child windows
When closing the last child window in the application, I need to disable menu items like Save and Print. I have all the logic written to do so, but when the last child window is closed from its own 'X' button instead of the parent window's Close menu item, the parent still thinks there's one form open for some reason.
After closing the last child window using its 'X' button, the menu items are still enabled. But if I click the Close or Close All menu buttons on the parent, then the menu items are disabled correctly.
I have a sub in the parent called UpdateControlState that uses MdiChildren.Length to handle menu items. I tried to use the code below but it never gets called:
Public Sub ClosedHandler(ByVal Sender As [Object], ByVal e As EventArgs) Handles MyBase.Closed
mainWin = Me.MdiParent
'If there are no child windows, then disable menu and toolbar items.
If mainWin.MdiChildren.Length = 0 Then
mainWin.UpdateControlState ()
End If
End Sub
How can I force an update of the parent window's mdiChildren collection? Should I?
Thanks
After closing the last child window using its 'X' button, the menu items are still enabled. But if I click the Close or Close All menu buttons on the parent, then the menu items are disabled correctly.
I have a sub in the parent called UpdateControlState that uses MdiChildren.Length to handle menu items. I tried to use the code below but it never gets called:
Public Sub ClosedHandler(ByVal Sender As [Object], ByVal e As EventArgs) Handles MyBase.Closed
mainWin = Me.MdiParent
'If there are no child windows, then disable menu and toolbar items.
If mainWin.MdiChildren.Length
mainWin.UpdateControlState
End If
End Sub
How can I force an update of the parent window's mdiChildren collection? Should I?
Thanks
If you do a trace or step through your code I believe you will find that the MDIClient is your mysterious window.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That's a great solution, Idle Mind.
By disposing the form, the MdiChildren.Length returns the correct value.
By disposing the form, the MdiChildren.Length returns the correct value.
ASKER
THANK YOU! You guys are awesome.