title: Closing Multiple Windows At Once
body: <p>I have a Windows forms app that opens up two other child form windows on a button click. If I click on the red X, I want all of the windows to close except the parent. Here is what I have but when I click on the red X I get an exception that says unable to access disposed object.</p>
  <p>This is what I have in my second child form. If the user doesn't select anything from the datagridview in the child window I click the x on that form I want that form and my other child form frmMessage to close and go back to the parent form.</p>
  <pre><code>void Fields(string from, string sub, bool rep)
          {
              string name = &quot;&quot;;
              txtReplyBool.Text = rep.ToString();
              if (rep == true)
              {
                 
                  foreach (var username in usernames)
                  {
                      name = user.Name;
                  }
                  email = from;
                  txtFrom.Text = name + &quot;(&quot; + email + &quot;)&quot;;
                  txtSubject.Text = subject;
  
  
              }
              else
              {
                  var sendto = new frmSendTo();
                  sendto.ShowDialog();
                  if (frmSendTo.email == null &amp;&amp; frmSendTo.name == null)
                  {
                      this.Close();
                      this.Dispose();
                      return;
                  }
                  else
                  {
                      email = frmSendTo.email;
                      txtFrom.Text = frmSendTo.name + &quot;(&quot; + email + &quot;)&quot;;
                  }
  </code></pre>
  <p>This is the parent:</p>
  <pre><code> private void btnSendNewMessage_Click(object sender, EventArgs e)
          {
              string from = &quot;&quot;;
              string subject = &quot;&quot;;
              bool reply = false;
              var sendmessage = new frmSendMessages(from, subject, reply);
              sendmessage.ShowDialog();
          }
  </code></pre>