winforms

Windows Form IsClosing flag?


Is there a way to know if a Windows Form is closing?

I would have to know from another class with a reference to the windows form. Something like:

if WinForm.IsClosing then ....


Solution

  • How about using the event Form.FormClosing Event

    The FormClosing event occurs as the form is being closed. When a form is closed, it is disposed, releasing all resources associated with the form. If you cancel this event, the form remains opened. To cancel the closure of a form, set the Cancel property of the FormClosingEventArgs passed to your event handler to true.