473,403 Members | 2,338 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,403 software developers and data experts.

How do I obtain Form.Close() result?

My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:

foreach(MyForm form in AllMyForms){
form.Close();
}
Application.Exit();

The OnClosing method [aka OnFormClosing in .NET 2.0] is overridden in MyForm. If the user has made changes to his form, this method asks him if he'd like to:
a) save his changes
b) forget changes and proceed to close the form
c) cancel the form closure loop and keep working on the form

In the event that the user chooses (c), OnClosing will cancel the closure operation. What I don't understand is why Form.Close() returns void. It seems like it should return a bool indicating whether or not the Close() operation was completed. Am I missing something? Given a call to Form.Close(), how can I tell if the form closure actually succeeded.

The only idea I can come up with is to check the Form.IsDisposed property immediately following the Close() call, with the assumption that if my modeless Form truly did close, it should also be Disposed. Is this the recommended approach?

Jules



In the
Nov 10 '05 #1
1 2066
Jules Winfield wrote:
The OnClosing method [aka OnFormClosing in .NET 2.0] is overridden in MyForm. If
Just to be clear, you should not use OnClosing in .Net 2.0, you should
use OnFormClosing instead as OnClosing is obsolete and may be removed
in the future. (but I assume you know this).
The only idea I can come up with is to check the Form.IsDisposed property immediately


What about handling the FormClosed event? This event is called after
the form has closed. Wherever you instantiate the form , wire up the
FormClosed event and then you will be notified when the form has
closed. This event won't be called if the closing is cancelled.

Hope this helps

Nov 10 '05 #2

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

Similar topics

1
by: comp.lang.php | last post by:
/** * Filter results according to given instruction * * @access private * @param object $result (reference) * @return object $filteredResult */ function &filterResults(&$result) { //...
1
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
2
by: Seth E Seligman | last post by:
I'm working on a web based file manager. The rename file function creates a new window with a form allowing the user to enter a new file name. Before the form gets submitted, I want to make sure that...
5
by: Kevin Myers | last post by:
How can one obtain obtain the height of a MS Access 2K form? There is a width property, but I don't see a corresponding height property. I need to obtain the height of the form so that I can...
2
by: Chien Lau | last post by:
Hi, At a certain point in my application, I have access to a Form object. I want to close that form: form.Close(); There are any number of reasons why this form might not close. A common...
1
by: Jules Winfield | last post by:
My WinForms application can have any number of top level forms open at a given time. If the user selects File|Exit, all of the forms are closed. The loop to close the forms looks something like this:...
0
by: natzol | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
4
by: Natalia | last post by:
Hello, I need to provide the ability to post file and some form elements via our website (asp.net) to the third party website (asp page). On http://aspalliance.com/236#Page4 - I found great...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
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?
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
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,...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.