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?
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.
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();