Closing Event in MDI Child Forms

G

Geoff Olding

In VB.Net, What events (if any), does an MDI child form
get when the application closes, which I can use to cancel
the close?
I am relying on the Closing event, which fires when the
form itself closes, however this doesn't fire when the
application closes. I can't find any alternative.
 
A

Armin Zingler

Geoff Olding said:
In VB.Net, What events (if any), does an MDI child form
get when the application closes, which I can use to cancel
the close?
I am relying on the Closing event, which fires when the
form itself closes, however this doesn't fire when the
application closes. I can't find any alternative.

It does fire when the application closes - unless you kill your app the hard
way by using "End" or "Application.Exit".
 
G

Geoff Olding

I don't get this result, I cannot get the event to fire whichever way I
close down the application
 
A

Armin Zingler

Geoff Olding said:
I don't get this result, I cannot get the event to fire whichever way
I close down the application

_How_ do you close the application? Is there an End statement or
Application.Exit anywhere? What if you set a breakpoint in the MDI
container's closing and/or closed events? Are they hit? What does the
callstack say when they are?

Can you reproduce it in a new project?
 
H

Herfried K. Wagner [MVP]

* Geoff Olding said:
I don't get this result, I cannot get the event to fire whichever way I
close down the application

Maybe you want to "subscribe" to the 'MdiParent''s 'Closing' event using
'AddHandler'/'RemoveHandler'.
 
G

Geoff Olding

In response to your questions:

The application is closed in two ways: - the user can either close down
the MDI form from the control box, or use an "Exit" menu item, which
just does the following:
Me.Close

The application stops on breakpoints in the Closing and Closed Events
(in th elater case, provided I temporarily remove some code I have on
the MDI form's "onClosed" event)
The Callstack on "Closing" is as follows:
Polygonal.exe!Polygonal.frmMdi.frmMdi_Closing(Object sender =
{Polygonal.frmMdi}, System.ComponentModel.CancelEventArgs e =
{System.ComponentModel.CancelEventArgs}) Line 1450 Basic
[<Non-user Code>]
Polygonal.exe!Polygonal.basGlobal.Main() Line 39 + 0xb bytes Basic

The problem can be reproduced in a new project - I have created a simple
project with an MDI form and an MDI child form and get the same problem
 
A

Armin Zingler

Geoff Olding said:
Thanks - this has done the trick

I don't understand this. You wrote:

"I am relying on the Closing event, which fires when the
form itself closes, however this doesn't fire when the
application closes."

Now the Closing event does fire?
 
G

Geoff Olding

I have resolved the issue by using the "AddHandler\RemoveHandler" idea
contained in another post.
For the record, the Closing event of the MDI form does fire OK, however
the Closing events of the MDI child forms do not fire.
 

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