title: C# close all forms
body: <p>I have a problem with my program.</p>
  
  <p>I have 3 Forms: First one opens a second form. Second one opens a third form or returns to the first form. The third form can open the first or second forms.</p>
  
  <p>This is how I open a second Form:</p>
  
  <pre><code>private void Open_second_form()
      {
          Form2 myForm = new Form2(Type_person);
          this.Hide();
          myForm.ShowDialog();
          this.Close();
      }
  </code></pre>
  
  <p>The rest of the forms I open exactly the same.</p>
  
  <p>Here is a code for how I close forms. Every Form has this method:</p>
  
  <pre><code>private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
          if (MessageBox.Show("Exit or no?",
                             "My First Application",
                              MessageBoxButtons.YesNo,
                              MessageBoxIcon.Information) == DialogResult.No)
          {
              this.Close();
              Environment.Exit(1);
          }
      }
  </code></pre>
  
  <p>When I open the third form I get 3 MessagesBoxes. If I open first form I got only 1 MessageBox.</p>
  
  <p>I want to close all forms while getting only one MessageBox.</p>
  
  <p>I tried a lot of solutions but none worked. 
  I tried <code>Application.exit();</code> </p>
  
  <p>Please help me :)</p>