Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Form.Close() returns void?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chien Lau - 02 Sep 2004 05:03 GMT
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...
Rakesh Rajan - 02 Sep 2004 05:49 GMT
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

> Hi,
>
[quoted text clipped - 14 lines]
>
> Thanks...
Herfried K. Wagner [MVP] - 02 Sep 2004 12:53 GMT
* "Chien Lau" <MontherInLau@grandson.pop> scripsit:
>     At a certain point in my application, I have access to a Form object. I
> want to close that form:
[quoted text clipped - 10 lines]
> 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".

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.