title: Closing event handlers C#
body: <p>I have two forms, Form 2 is inheriting from Form 1.</p>
  
  <p>What I need to do is that when I close both Form 1 and Form 2 another form which asks if user is sure to quit appears. Then if user clicks Yes, another form which asks if the user wants to save the game appears if and only if the form which the user closes is Form 2 and not Form 1 since for Form 1 there is no saving necessary. </p>
  
  <p>This is what I managed to do:</p>
  
  <p>// These are the Form 1 closing and closed event handlers:</p>
  
  <pre><code>private void GameForm_FormClosing(object sender, FormClosingEventArgs e)
  {
      e.Cancel = true;
      SureClose sc = new SureClose();
      sc.StartPosition = FormStartPosition.CenterScreen;
      sc.Show();
  }
  
  private void GameForm_FormClosed(object sender, FormClosedEventArgs e)
  {
      MainMenu menu = new MainMenu();
      menu.Show();
  }
  </code></pre>
  
  <p>Then in Sure Close:   // Please note that Tournament is Form 2 inheriting from GameForm (Form 1)</p>
  
  <pre><code> private void yesButton_Click(object sender, EventArgs e)
   {
          this.Hide();
  
          if (GameForm.ActiveForm is Tournament)
          {
              SaveGame sg = new SaveGame();
              sg.StartPosition = FormStartPosition.CenterScreen;
              sg.Show();
          } 
          else 
          {
              GameForm.ActiveForm.Close();
          }
      }
  
      private void noButton_Click(object sender, EventArgs e)
      {
          this.Hide();
      }
  </code></pre>
  
  <p>// This is the SaveGame Form:</p>
  
  <pre><code> private void saveButton_Click(object sender, EventArgs e)
   {
       // Still to do saving!
   }
  
   private void dontSaveButton_Click(object sender, EventArgs e)
   {
       this.Hide();
       GameForm.ActiveForm.Close();
   }
  </code></pre>
  
  <p>The problem is that when in the yesButton event handler in SureClose Form I have GameForm.ActiveForm.Close(), this is going back to the GameForm Closing event handler therefore the SureClose dialog is appearing again.</p>
  
  <p>I tried doing:   if (e.CloseReason() == CloseReason.UserClosing) 
  but obviously it doesn't work either because the reason of closing will always be the user :/</p>
  
  <p>How can I solve this?
  Thanks a lot for any help !</p>