title: Cannot access a disposed object error
body: <p>I am getting the error message <strong>Cannot access a disposed object.
  Object name: 'ApplicationProperties'.</strong> when I tryo to re-open a form after closing it. I have noticed this is from exiting forms, and exiting is <strong>"Disposing"</strong> of them, so I have put the following code in all of my accept buttons, and cancel buttons (any button that closes a form).</p>
  
  <pre><code> this.Hide(); 
   this.Parent = null;
  </code></pre>
  
  <p>This code is just hiding the form. <strong>Not closing the form.</strong></p>
  
  <p>So what my problem is, is that when I click the 'x' button on the form, then try to re-open the form I still get the error message. I have tried a couple differnet ways to modify the exiting funciton of the form such as:</p>
  
  <pre><code>    private void ApplicationProperties_FormClosing(object sender, FormClosingEventArgs e)
      {
          //Hiding the window, because closing it makes the window unaccessible.
          this.Hide();
          this.Parent = null;
      }
  </code></pre>
  
  <p>But this has brought me no luck. I was wondering if anyone knows how to solve this problem. Here is the code that is working for me inside my cancel and accept buttons. It is the same for all of my buttons that close forms.</p>
  
  <pre><code>    private void OptionsCancelbtn_Click(object sender, EventArgs e)
      {
          //Hiding the window, because closing it makes the window unaccessible.
          this.Hide();
          this.Parent = null;
      }
  </code></pre>
  
  <p>I have declared the instance at the top of my class on form1, and have a button inside form1 that opens form2.</p>
  
  <pre><code>public partial class MainBox : Form
  {
      //Making a name for the ApplicationProperties form. It can be opened when called.
      ApplicationProperties ApplicationPropertiesWindow = new ApplicationProperties();
      private void ApplicationPropertiesbtn_Click(object sender, EventArgs e)
      {
          //Show the properties window.
          ApplicationPropertiesWindow.Show();
      }//End ApplicationProperties button.
   }
  </code></pre>
  
  <p>After I close the program with the 'x' button on the second form I cannot access form2 again because of the error message firing at <code>ApplicationPropertiesWindow.Show();</code></p>
  
  <p>Inside form2 I have the following code:</p>
  
  <pre><code>public partial class ApplicationProperties : Form
  {
      //Creates and sets the instance MainBoxWindow.
      public MainBox MainBoxWindow { get; set; }
  </code></pre>