473,573 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2987
" Academic" <ac************ @a-znet.comwrote in message
news:OH******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.phx.gbl...
>" Academic" <ac************ @a-znet.comwrote in message
news:OH******* *******@TK2MSFT NGP03.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******** ******@TK2MSFTN GP02.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******** ******@TK2MSFTN GP03.phx.gbl...
>>" Academic" <ac************ @a-znet.comwrote in message
news:OH****** ********@TK2MSF TNGP03.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
2512
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 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...
4
1818
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 do this for new records; tag each record with a boolean value. On clicking OK, these are all set to True and the form closes. If they Cancel the...
6
8553
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 your form Private Sub OtherInitialize( AddHandler Me.Closing, AddressOf Me.Form1_Cance End Sub 'OtherInitializ Protected Sub Form1_Cancel(sender...
3
2768
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 the value to False, but I would have expected it to be False on entry. TIA Charles
2
1536
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 Closing events even after it receives an e.Cancel=true.
3
6357
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 contains unsaved data. If the user clicks "No" then the code sets e.Cancel = True, which cancels the closure. This works just great. But when the user...
2
3275
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 cancel = true after the save button has been clicked, the update statements in the click event of the save button still occur but nothing gets saved,...
21
9144
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 the cancel button, the textbox.validating is being called. I don't want it to be since they are exiting the screen the validation doesn't have to be...
6
7716
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 IsNull(Me!NotExpectingGreenTickets) Then DoCmd.CancelEvent Exit Sub End If End Sub
0
7686
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7771
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8060
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6406
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5289
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3730
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1296
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.