title: Validating form close infinite loop
body: <p>I am creating a small project using winforms + c#, I have an issue in that I am using a second form in my project as a dialogue box. When the user attempts to close this I'd like to provide them with a confirmation screen to prevent any data loss in closing the form. This dialogue box form will also feature a 'home' button, closing the dialogue box form leaving them with the main window again. The problem arises when the windows X button is pressed at the top of the screen requiring me to set up an 'on form close' event to manage. This however creates an infinite loop with my current code shown below. Is there any way to avoid this?</p>
  
  <pre><code>private void frmCreateRoute_FormClosing(object sender, FormClosingEventArgs e)
  {
  
    DialogResult Safe_to_exit_check = MessageBox.Show("Are you sure you would like to go to the home screen? \n(Any entered data will be lost.)", "", MessageBoxButtons.YesNo);
  
    if (Safe_to_exit_check == DialogResult.Yes)
    {
      this.Close();
    }
  }
  </code></pre>
  
  <p>and a simple:</p>
  
  <pre><code>private void Home_button_Click(object sender, EventArgs e)
  {
    this.Close();
  }
  </code></pre>
  
  <p>for the home button.</p>
  
  <p>Thanks</p>