showing a form twice
-
i have a stupid problem. i show my form, close it and try to show it again, but i get an error saying i'm trying to access a disposed object. how can i prevent that? i must be missing something obvious. thanks.
You're trying to reuse a disposed reference. This occurs because you have created an object which has subsequently been disposed. What you need to do is something like the following:
private void CreateMyForm() { using (MyForm myForm = new MyForm()) { myForm.Show(); } }
Then call CreateMyForm whenever you want to create an instance of this form.
Deja View - the feeling that you've seen this post before.
-
i have a stupid problem. i show my form, close it and try to show it again, but i get an error saying i'm trying to access a disposed object. how can i prevent that? i must be missing something obvious. thanks.
You can use GC::KeepAlive(yourForm)
-
i have a stupid problem. i show my form, close it and try to show it again, but i get an error saying i'm trying to access a disposed object. how can i prevent that? i must be missing something obvious. thanks.
I've had a similar problem. My solution was to catch the FormClosing event, and when
e.CloseReason == CloseReason.UserClosing
, sete.Cancel
to true and Hide the form.A little learning is a dangerous thing; Drink deep, or taste not, the Pierian Spring. —Alexander Pope