title: Hiding MDI child forms on close using C#
body: <p>I'm currently building a multiple-document interface application, but I'm having a problem when the child forms are closed via the x button. When the form is closed, the only way to show it again is to create a new instance of that particular form, meaning all of the data contained within the previous form is lost.</p>
  
  <p>I have attempted to set the form closing event to simply hide the form, but then when the user closes the main parent form, the application does not exit.</p>
  
  <p>Is there a way around this?</p>
  
  <p>Here is the code I am currently using for my child forms' form closing event:</p>
  
  <pre><code>private void ParameterForm_FormClosing(object sender, FormClosingEventArgs e)
  {
      if (e.CloseReason != CloseReason.FormOwnerClosing)
      {
          this.Hide();
          e.Cancel = true;
      }
  }
  </code></pre>
  
  <p>With this code, the main form's x button must be clicked twice, once to close the child form and once to close the main form.</p>