jango_fett
Member
- Joined
- Jun 15, 2005
- Messages
- 23
- Programming Experience
- Beginner
[RESOLVED] MDI Form and MDI Children Question
Hi, all. I'm a newcomer to VB .NET and I'm having a hard time with MDI forms. Specifically, whenever the user attempts to close the MDI form, I need to make sure that all of its children forms are closed. If they are not, I display a message asking the user if they really want to leave.
For example, I state the child form like this:
To open it, the code goes:
The following code goes in the variable's Closed event:
Then, I code in the MDI form Closing event:
The above code seems to work, but the thing is that I have many children forms and to validate each one of them is overkill. Is there a better way to reference them all at once? Any help would be appreciated. Many thanks!
Hi, all. I'm a newcomer to VB .NET and I'm having a hard time with MDI forms. Specifically, whenever the user attempts to close the MDI form, I need to make sure that all of its children forms are closed. If they are not, I display a message asking the user if they really want to leave.
For example, I state the child form like this:
VB.NET:
Friend WithEvents MyChild as frmMDIChild
VB.NET:
MyChild = New frmMDIChild
MyChild.MdiParent = Me
MyChild.Show()
VB.NET:
Private Sub MyChild_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyChild.Closed
MyChild = Nothing
End Sub
VB.NET:
Private Sub frmMDI_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If MyChild Is Nothing = False Then
if MsgBox("There are still open windows. Really exit?", _
MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Exit") _
= MsgBoxResult.No Then
e.Cancel = True
End If
End Sub
Last edited: