473,394 Members | 1,642 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,394 software developers and data experts.

e.Cancel = True in MDI Child Closing event

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 appears, I click "No", but the form (and
the application) closes anyway.

In VB6, aborting the closing in a form's QueryUnload event would cancel the
closure of the application in this circumstance. I'm eager to try to obtain
this behaviour in VB.NET as I'm worried about people losing work that they
have entered into these forms.

Is there any way to achieve this?

Many thanks,

--

(O) e n o n e
Nov 21 '05 #1
3 6340
The expected behaviour is that if you attempt to close an MDI parent then
the Closing event of each MDI child will fire. If any one of these child
forms sets e.Cancel = True then no further Closing events will be fired, and
the MDI parent will not close. I have this scenario and it works as
described.

Can you confirm that with one MDI parent and one Child, clicking the MDI
Parent close button does not fire the child closing event?

Charles
"Oenone" <oe****@nowhere.com> wrote in message
news:CO***************@newsfe2-win.ntli.net...
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 appears, I click "No", but the form
(and
the application) closes anyway.

In VB6, aborting the closing in a form's QueryUnload event would cancel
the
closure of the application in this circumstance. I'm eager to try to
obtain
this behaviour in VB.NET as I'm worried about people losing work that they
have entered into these forms.

Is there any way to achieve this?

Many thanks,

--

(O) e n o n e

Nov 21 '05 #2
Charles Law wrote:
The expected behaviour is that if you attempt to close an MDI parent
then the Closing event of each MDI child will fire. If any one of
these child forms sets e.Cancel = True then no further Closing events
will be fired, and the MDI parent will not close. I have this
scenario and it works as described.


Hmm, I just set up a project to test this and it worked exactly as you
described.

There must be something else going on in my real application -- I'll
investigate.

Thanks for your help,

--

(O) e n o n e
Nov 21 '05 #3
Oenone wrote:
There must be something else going on in my real application -- I'll
investigate.


In the Closing event of the MDI Container form, I had some code which closed
the entire application down. This was a hang-over from the VB6
implementation and was unsurprisingly causing the behaviour I described.
With this removed it's all working perfectly.

Thanks again,

--

(O)enone
Nov 21 '05 #4

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...
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
10
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
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...
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...
4
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...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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...
0
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...

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.