title: How to display a MessageBox in a FormClosing event to prompt for cancellation?
body: <p>I am using this code but it does not work, what am I doing wrong?</p>
  
  <pre><code>private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  {
      if (MessageBox.Show("This will close down the whole application. Confirm?", "Close Application", MessageBoxButtons.YesNo) == DialogResult.Yes)
      {
          MessageBox.Show("The application has been closed successfully.", "Application Closed!", MessageBoxButtons.OK);
      }
      else
      {
          e.Cancel = true;
          this.Activate();
      }
  }
  </code></pre>