473,698 Members | 2,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If e.Cancel Then Exit Sub in Closing event

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.

Is that the case?

Does the If make sense?

Can anyone shed some light on this?

Thanks for helpful comments


Nov 21 '05 #1
2 1541

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.

HTH,

Sam
On Fri, 7 Jan 2005 11:43:26 -0500, " Just Me" <gr****@a-znet.com>
wrote:
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.

Is that the case?

Does the If make sense?

Can anyone shed some light on this?

Thanks for helpful comments


Nov 21 '05 #2
thanks a lot
"Samuel R. Neff" <bl****@newsgro up.nospam> wrote in message
news:22******** *************** *********@4ax.c om...

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.

HTH,

Sam
On Fri, 7 Jan 2005 11:43:26 -0500, " Just Me" <gr****@a-znet.com>
wrote:
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.

Is that the case?

Does the If make sense?

Can anyone shed some light on this?

Thanks for helpful comments

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2517
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 can't seem find how to catch the child window's cancel of the Closing event, so even if the user...
4
1826
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 False records are deleted and the form closes.
6
8573
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 As Object, e As CancelEventArgs If Not myDataIsSaved The
3
2771
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
3
6368
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 closes the MDI parent form, the cancellation seems to be completely ignored. The MessageBox...
2
3290
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, which is OK. Except that I pop a message box in the click event after the update statements have...
21
9166
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 done. How can I do that.
4
3001
by: Academic | last post by:
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?
6
7725
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
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4369
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.