473,383 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Put If e.Cancel Then Exit Sub in Closing event

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
4 2972
" 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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ron L | last post by:
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...
4
by: Deano | last post by:
Alot of my forms are bound. I would like to offer a Cancel option so that they can make as many changes as they like and still Cancel out without making any changes. I have one idea of how to...
6
by: Carl | last post by:
Hi you al I am new to this stuff and I found this code to close a form in the help files and I do not understand it or where its goe ' Calls this method from the InitializeComponent() method of...
3
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set...
2
by: Just Me | last post by:
I've seen this in example code: Private Sub Studio_Closing(ByVal sender A..snip.. Handles MyBase.Closing If e.Cancel Then Exit Sub ....snip... It would make sense if Windows keeps doing...
3
by: Oenone | last post by:
I'm writing an application with various MDI child forms. In the Closing event of many of the forms, I have code that asks the user whether he is sure he wants to close the form, because it...
2
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
6
by: MLH | last post by:
I have a form, frmUSPSReturnReceipts, with a control named NotExpectingGreenTickets. The control's Exit event procedure follows: Private Sub NotExpectingGreenTickets_Exit(Cancel As Integer) If...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.