Null object reference has nothing to do with form status. It can be closed, activated — the instance of its class remains valid. I have no idea why would you need to check up if the form is closed. I'm pretty much sure you never need it. Some advice and example:
If you want to show a form again, never close it but hide it instead. Here is how:
public class MyForm : Form {
public override void OnFormClosing(FormClosingEventArgs eventArgs) {
base.OnFormClosing(eventArgs);
if (eventArgs.ClosegReason == System.Windows.Forms.CloseReason.UserClosing) {
eventArgs.Cancel = true;
this.Hide();
}
}
}
Also, if you do it right, form operations should not depend on its status. For example,
Form.Show
shows the form no matter if it was hidden or shown before the call.
See
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx[
^].
If you still want to know of the form was closed, you can add some Boolean flag as a field of the form class, override
OnFormClosed
and set this flag to true, which would indicate the form was closed. Again, I think you won't need it and won't find a good use of it; I added this advice only to formally answer your question.
—SA