MDI Child Window Closing event not raised

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!
 
A

Armin Zingler

chris in grimsby said:
If you put the MDIParent and MDIChild in a Windows application, it
all works ok!

Here there's no difference. As long as you use showdialog, the closing event
of the child does not fire, no matter where the forms are.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top