Open the closed form

Sephiroth111 picture Sephiroth111 · Mar 10, 2012 · Viewed 14.1k times · Source

I'm wondering how I can open again the closed form from using this.Close(). Every time I'm trying to open the closed form using Mainmenu.Show(), the exception throws an error "cannot access the disposed object. Object name: Mainmenu".

How can I open it again?

Answer

Andrei G picture Andrei G · Mar 10, 2012

When the Close method is called on a Form you cannot call the Show method to make the form visible, because the form's resources have already been released aka Disposed. To hide a form and then make it visible, use the Control.Hide method.

from MSDN

If you want to re-open a form that has been closed, you need to re-create it again the same way you created-it at first:

YourFormType Mainmenu=new YourFormType();
Mainmenu.Show();