By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

How to cancel MDI Application Closing from child windows

P: n/a
I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child window
catches its Closing event and cancels it if the user wants to save the data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user selects
cancel to the closing event the application closes anyway. Can anyone point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I clicked
send. DOH!
Sep 26 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
There are a couple of things you can do, and it is up to you how you
implement them.

My recommendations

First: Do not issue the Application.Exit or Application.End until after all
your child forms are closed and all state data is preserved.

Second: On _mainView_Closing count the number of opened mdichildren and
set e.Cancel = true if the number is greater than 0

Third: Move your Application.End or Application.Exit statement in either
_mainView.Closed or more remote location.
sample:

sub _mainView_Closing

for each f as form in _mainView.mdichildren
f.close
next

if _mainView.mdichildren.length > 0 then e.cancel = true

end sub

sub _mainView_Closed
End
end sub
"Ron L" <ro**@bogus.Address.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child
window
catches its Closing event and cancels it if the user wants to save the
data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user
selects
cancel to the closing event the application closes anyway. Can anyone
point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I
clicked send. DOH!

Sep 27 '05 #2

P: n/a
AMDRIT

Thank you for your response. It worked great! I had been trying to pass on
the cancel rather than just see if anything canceled after the fact.

Ron L

"AMDRIT" <am****@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
There are a couple of things you can do, and it is up to you how you
implement them.

My recommendations

First: Do not issue the Application.Exit or Application.End until after
all your child forms are closed and all state data is preserved.

Second: On _mainView_Closing count the number of opened mdichildren and
set e.Cancel = true if the number is greater than 0

Third: Move your Application.End or Application.Exit statement in either
_mainView.Closed or more remote location.
sample:

sub _mainView_Closing

for each f as form in _mainView.mdichildren
f.close
next

if _mainView.mdichildren.length > 0 then e.cancel = true

end sub

sub _mainView_Closed
End
end sub
"Ron L" <ro**@bogus.Address.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child
window
catches its Closing event and cancels it if the user wants to save the
data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user
selects
cancel to the closing event the application closes anyway. Can anyone
point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I
clicked send. DOH!


Sep 28 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.