Form.Close() returns void?

  • Thread starter Thread starter Chien Lau
  • Start date Start date
C

Chien Lau

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...
 
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 said:
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".
 
Back
Top