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

Put If e.Cancel Then Exit Sub in Closing event

P: n/a
Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

Does your answer also apply the MdiChildren?

Thanks


Nov 7 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
" Academic" <ac************@a-znet.comwrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

Does your answer also apply the MdiChildren?
If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>
Thanks


Nov 8 '06 #2

P: n/a
Michael C wrote:
" Academic" <ac************@a-znet.comwrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
I guess what I'm asking is will that work. If one form sets e.cancelled to
true will e.cancel be true when the next form receives a closing event?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
Just wondering, will the forms always receive the event in a
predictable order?

Nov 8 '06 #3

P: n/a
I hate to generalize from a test so I won't. But in my situation a test
shows that if I have a MdiContainer open and a bunch of standard forms also
open and a bunch of MdiChildren also open, the all the standard forms
receive the Closing event even if one cancels. I'm closing the forms one at
a time in the MdiContainer Closing routine so maybe that makes a difference.

Also, e.Cancel is always false on entering except for MdiChildren where
e.Cancel remains true once a closing event sets it to True.

Not very neat.

Also, in this test, the forms received the event in the order they were
open - made no difference which had focus or which was topmost

"Michael C" <no****@nospam.comwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
>" Academic" <ac************@a-znet.comwrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
>Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another when
its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled
to true will e.cancel be true when the next form receives a closing
event?

Does your answer also apply the MdiChildren?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>>
Thanks



Nov 8 '06 #4

P: n/a
I found this on the Internet. Agrees with my test except for the
MdiChildren value of e.cancel. Also, I can't think of a situation where if a
user canceled the app shutdown you would want to run all the other form
events but I suppose it could happen.

guess it's time to move on.

Thanks again

The event is broadcast by the multi-cast delegate just like any other
event. This delegate has no knowledge of the Cancel property or what
it is for. It always sends the event to all subscribed delegates.
Also, there are situations where you have multiple listeners of the
closing event and you want them to all fire off even if one of them
says to cancel.
If what you're doing doesn't need to run if something else cancelled,
then it's good practice to add this check at top of routine.


" Academic" <ac************@a-znet.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
>I hate to generalize from a test so I won't. But in my situation a test
shows that if I have a MdiContainer open and a bunch of standard forms also
open and a bunch of MdiChildren also open, the all the standard forms
receive the Closing event even if one cancels. I'm closing the forms one
at a time in the MdiContainer Closing routine so maybe that makes a
difference.

Also, e.Cancel is always false on entering except for MdiChildren where
e.Cancel remains true once a closing event sets it to True.

Not very neat.

Also, in this test, the forms received the event in the order they were
open - made no difference which had focus or which was topmost

"Michael C" <no****@nospam.comwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
>>" Academic" <ac************@a-znet.comwrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
>>Does it make sense to put this

If e.Cancel Then Exit Sub

at the beginning of form closing events so if the user cancels the app's
exiting in one Closing routine he will not be asked again by another
when its form Closing routine is run?

I guess what I'm asking is will that work. If one form sets e.cancelled
to true will e.cancel be true when the next form receives a closing
event?

Does your answer also apply the MdiChildren?

If one form receives a closing event and cancels it, then no other forms
will receive the closing event. So your code is unnecessary.
>>>
Thanks




Nov 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.