Search code examples
c#.netwinformsgarbage-collectiondispose

How to show form after it was closed?


I have a MDI application with couple of windows. Is there any way to disable disposing form after it was closed by the user. I want to be able to reopen that form just by calling form.Show() method.


Solution

  • You could use 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.

    This should do the same thing as you'd do with Form.Show()