Mike Pischke

Mike Pischke

  • NA
  • 11
  • 0

How to ignore a leave event when a cancel button is clicked

Aug 9 2010 9:49 AM
Consider this simple leave event from a text box control in a visual studio form:

private void dscr_Leave(object sender, EventArgs e)
{
      if (dscr.Text == null)
            MessageBox.Show("You must supply a description");
}

Assume there is a "cancel" button on the screen, and focus is in the "dscr" text box, and it's blank.   You click the cancel button. As a beginner, I'm struggling on how to ignore this leave event when a cancel button is clicked.   I've searched quite a while, and cannot find how to accomplish this.   The leave event will fire before the click, but there's got to be some way to know the click event is coming, and avoid unnecessary validation.   Can anyone point me to any examples of how to handle this situation, or direct me as to how to accomplish this?