Reputation: 4196
I have a custom Form class, which is reacting to the Closing
event, like this:
class MyForm: Form
{
...
private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
{
if ( ... )
e.Cancel = true;
}
...
}
Now, somewhere else, I call Close()
on this form:
MyForm frm;
...
frm.Close();
Question: After calling Close()
, how can I find out whether the form was really closed, or if the closing was cancelled in the Closing
Event?
The Close()
method does not return a value, and it also does not throw an exception.
Upvotes: 1
Views: 1361
Reputation: 28499
You can check the IsHandleCreated
property.
frm.Close();
if(frm.IsHandleCreated)
{
// Closing the form was cancelled, the form is still there
}
Upvotes: 3