title: How to prevent or block closing a WinForms window?
body: <p>How can I prevent window closing by showing a <code>MessageBox</code>? (Technology:<code>WinForms</code> with <code>C#</code>)</p>
  
  <p>When the close event occurs I want the following code to be run:</p>
  
  <pre><code>private void addFile_FormClosing( object sender, FormClosingEventArgs e ) {
      var closeMsg = MessageBox.Show( "Do you really want to close?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
  
      if (closeMsg == DialogResult.Yes) {
          //close addFile form
      } else {
          //ignore closing event
      }
  }
  </code></pre>