The problem: A dialog's FormClosing() event is raised if it's a child, ie it's Owner property is set to the parent form, but NOT if it's a child-of-a-child. So closing the main form does not call the closing event on any grandchildren dialogs.
The Details: A dialog prompts to "Save Changes?", with YesNoCancel buttons, in the FormClosing() event. Clicking Cancel keeps the dialog open, ie cancel closing.
Private Sub Dialog_FormClosing(...) Handles Me.FormClosing
If MessageBox.Show("Save Changes?", YesNoCancel) = No Then
e.Cancel = True
End If
End Sub
So instantiating a new dialog, with its Owner property set...
// called from the main form
Dim dlg As New Dialog
dlg.Owner = Me
dlg.Show()
... has the benefit that the dialog will prompt to save if the user tries closing the owner/parent. Clicking Cancel will keep the dialog open, and it's owner as well.
But if that same dialog was shown from a child of a parent (also with it's owner property set), and not from a parent:
// called from another child
Dim dlg As New Dialog
dlg.Owner = Me
dlg.Show()
Then the FormClosing() event on the child does not raise, if the top-most parent is closed.
Is this a know design limitation in the framework? Is there anything I should consider before I start hacking a nasty solution for this?
Thanks for any replies.