title: C#: How to cancel the close action for a button that's set as the Accept or Cancel button on a form?
body: <p>I have a button <code>btnOK</code> on my form, with a <code>DialogResult</code> property of <code>OK</code>.  The form's <code>AcceptButton</code> property is set to <code>btnOK</code>.  So if I click the button, the form closes automatically.</p>
  
  <p>Now, inside the <code>btnOK_Click()</code> method, I want to ability to cancel out of the close action, e.g. if there was an error I want to show a message box and not close the form.</p>
  
  <p>How do I do it?</p>