473,563 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Exi t();

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 2092
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
1813
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) { // STATIC OBJECT ARRAY METHOD global $section;
1
4180
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 in IE as well as FireFox. This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL 4.1.8 and it works fine. The problem server is...
2
33782
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 a valid file name (no "/" or "\" characters) was entered. If the validation functions returns true, the form should be submitted and the window...
5
18612
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 dynamically resize an object on the form in the form's Form_Resize method when a user resizes the form, both horizontally and vertically. Thanks,...
2
4985
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 reason might be that the user answered "No" when the form's OnClosing() override asked him "Are you sure you want to close this form?"
1
356
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: foreach(MyForm form in AllMyForms){ form.Close(); } Application.Exit(); The OnClosing method is overridden in MyForm. If the user has made...
0
1460
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 advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST -...
4
12693
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 advices but still having troubles... it might some obvious error that I am making but I just dont see it. ==================FIRST -...
11
5274
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 / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
0
7885
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. ...
1
7638
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
7948
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
5213
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
3642
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
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
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.