I'm getting ObjectDisposedException was unhandled
with message Cannot access a disposed object.
This happens when initialize this child form at the beginning of my class by MyForm myForm = new MyForm();
and then adding some text to my text box of that form by myForm.txtBox.AppendText("Text");
and then opening my new form my form by using some button with code myForm.Show();
. Now when my job is done I can close the form. Now, when I want to display the data again I'm getting that exception.
I want to keep the content of text box in my new form, but it seems like there is a problem that I haven't disposed everything in it.
How to avoid this so I can view the new forms content any time I press button?
From the MSDN documentation on
Form.Close
:You could capture the
Form.Closing
event on the form, cancel the event, and hide the form instead ofClose
ing it.