Telling if you have open Children?

Troy

Well-known member
Joined
Feb 7, 2005
Messages
153
Programming Experience
10+
Is there a way to tell programmatically if you have any open MDI children windows?

I need to be able to enable some buttons only if there are open MDI Children.
 
Why would one refuse to close? While indx never changes from zero the length does change and eventually equals zero so it exits the loop.
 
You can Cancel the Form.Closing event by setting e.Cancel=True, if none of your forms does this there is no need to make this check.

The problem you had with the MdiChildren(index).Close was that you had to loop from top down step -1.
 
Yeah I figured that out. Thanks guys!
 
I dont know what happens if one form is busy (perhaps showing a modal dialog or message box) when you try to close it; its called defensive programming..:D
 
If one form is displaying a dialog the application becomes inaccessible and you can't click this menu close.

If you created a new "MDI Parent Form" that have most standard MDI stuff already you will see this code for the 'Close all' Window menu:
VB.NET:
For Each ChildForm As Form In Me.MdiChildren
    ChildForm.Close()
Next
 
If one form is displaying a dialog the application becomes inaccessible and you can't click this menu close.

Sorry, when i said "you try to close it" i didnt mean "the user clicks a close button" I meant, the programmer calls Close(). How this happens? I dont know.. Say for arguments sake it happens on a timer.. the Timer fires just as a dialog is on show; I dont know what happens if the code calls on a window to close() when it is busy..
 
Here is happens with mnuWindowCloseAllOpenRecords.Click.
 
Back
Top