C
chris in grimsby
MDIChild Window Closing event not raised when MDI Parent is in a class
library!
Intructions to recreate problem:
1. Create a ClassLibrary project
2. Add an MDIParent form and a form that will be an MDIChild form
3. In the Closing event of both forms add debug code so that you can
see when they are called
<MDI PARENT FORM CODE>
Private Sub MDIParent_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Debug.WriteLine("MDIParent_Closing " & Now & " " &
e.Cancel.ToString)
End Sub
Private Sub MDIParent_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim f As New MDIChild
f.MdiParent = Me
f.Show()
End Sub
<MDI CHILD FORM CODE>
Private Sub MDIChild_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Debug.WriteLine("MDIChild_Closing " & Now & " " &
e.Cancel.ToString)
End Sub
4. Add a Windows Application to act as the client and set the
reference:
<MODULE1 CODE>
Sub Main()
Dim f As New ClassLibrary1.MDIParent
f.ShowDialog()
End Sub
5. Run the application. Click the X close button on the MDIParent and
you will see that the MDIParent_Closing event fires but not the
MDIChild!
If you put the MDIParent and MDIChild in a Windows application, it all
works ok!
library!
Intructions to recreate problem:
1. Create a ClassLibrary project
2. Add an MDIParent form and a form that will be an MDIChild form
3. In the Closing event of both forms add debug code so that you can
see when they are called
<MDI PARENT FORM CODE>
Private Sub MDIParent_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Debug.WriteLine("MDIParent_Closing " & Now & " " &
e.Cancel.ToString)
End Sub
Private Sub MDIParent_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim f As New MDIChild
f.MdiParent = Me
f.Show()
End Sub
<MDI CHILD FORM CODE>
Private Sub MDIChild_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Debug.WriteLine("MDIChild_Closing " & Now & " " &
e.Cancel.ToString)
End Sub
4. Add a Windows Application to act as the client and set the
reference:
<MODULE1 CODE>
Sub Main()
Dim f As New ClassLibrary1.MDIParent
f.ShowDialog()
End Sub
5. Run the application. Click the X close button on the MDIParent and
you will see that the MDIParent_Closing event fires but not the
MDIChild!
If you put the MDIParent and MDIChild in a Windows application, it all
works ok!