|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Put If e.Cancel Then Exit Sub in Closing eventDoes 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
Show quote
Hide quote
" Academic" <academicNOSPAM@a-znet.com> wrote in message If one form receives a closing event and cancels it, then no other forms news:OHW4WosAHHA.4592@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? will receive the closing event. So your code is unnecessary. Show quoteHide quote > > > > Thanks > > > > Michael C wrote:
> " Academic" <academicNOSPAM@a-znet.com> wrote in message Just wondering, will the forms always receive the event in a> news:OHW4WosAHHA.4592@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. predictable order? 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 Show quoteHide quote "Michael C" <nospam@nospam.com> wrote in message news:uMPo5zsAHHA.4992@TK2MSFTNGP03.phx.gbl... >" Academic" <academicNOSPAM@a-znet.com> wrote in message >news:OHW4WosAHHA.4592@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 >> >> >> >> > > 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. Show quoteHide quote " Academic" <academicNOSPAM@a-znet.com> wrote in message news:Ol5$9P0AHHA.3620@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" <nospam@nospam.com> wrote in message > news:uMPo5zsAHHA.4992@TK2MSFTNGP03.phx.gbl... >>" Academic" <academicNOSPAM@a-znet.com> wrote in message >>news:OHW4WosAHHA.4592@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 >>> >>> >>> >>> >> >> > > |
|||||||||||||||||||||||