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

Form.Close() returns void?

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?"

It seems like Form.Close() should return a *bool* indicating whether or
not the closure was successful. I can think of lots of tricky workarounds to
get a hold of this value, but the fact that Close() isn't designed to return
this crucial value directly makes me wonder if I'm using the wrong approach
to close the form. Is there another method that I should consider?

Thanks...
Nov 16 '05 #1
2 4969
Hi Chien,

I do think that calling Form.Close is indeed the right way of closing. But
yes, as you said, it seems like there is no intimation from the Close method
directly on whether it closed successfully or not - something like a return
value as you suggested.

But of course, indirect methods exist: You could handle the Form.Closed
event in case want to get notified when a form is completely closed. In
addition, if you are using Application.Exit anywhere, you might have to
handle all forms individually to make sure that your form's get notification
of the event.

- Rakesh

"Chien Lau" wrote:
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?"

It seems like Form.Close() should return a *bool* indicating whether or
not the closure was successful. I can think of lots of tricky workarounds to
get a hold of this value, but the fact that Close() isn't designed to return
this crucial value directly makes me wonder if I'm using the wrong approach
to close the form. Is there another method that I should consider?

Thanks...

Nov 16 '05 #2
* "Chien Lau" <Mo**********@grandson.pop> scripsit:
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?"

It seems like Form.Close() should return a *bool* indicating whether or
not the closure was successful. I can think of lots of tricky workarounds to
get a hold of this value, but the fact that Close() isn't designed to return
this crucial value directly makes me wonder if I'm using the wrong approach
to close the form. Is there another method that I should consider?


\\\
Me.DialogResult = DialogResult.OK
Me.Close()
///

Then you can check the form's dialog result to see if the form was
closed by pressing "OK" or "Cancel".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 16 '05 #3

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

Similar topics

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...
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
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:...
3
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. ...
2
by: amil [c#newbie] | last post by:
Hi all, I am using the Notify Icon sample that came with .Net Docs and was able to run it. However, I want to start the form as minimized. I have the ShowInTaskbar = false and in the this is...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.