How to Cancel a Cancel Button event

  • Thread starter Thread starter Eric T.
  • Start date Start date
E

Eric T.

When the user presses Cancel on my form, I want there to be an opportunity to
cancel the cancel, i.e. "Do you really want to abort the changes you've
made". If the user presses N, I don't want it to exit. If the user presses
Y, I set the DialogResult to Cancel and call this.Close(). I don't do
anything if the user presses N, but the form closes anyways. How do I stop
the form from closing?
Thanks
PS - The cancel button object is registered in the form as the CancelButton.
 
Hi,

You can use the Form.FormClosing event, to cancel the close, just set the
FormClosingEventArgs parameters Cancel property to true.

Hope You find this useful.
-Zsolt
 
Eric T. said:
When the user presses Cancel on my form, I want there to be an opportunity
to
cancel the cancel, i.e. "Do you really want to abort the changes you've
made". If the user presses N, I don't want it to exit. If the user
presses
Y, I set the DialogResult to Cancel and call this.Close(). I don't do
anything if the user presses N, but the form closes anyways. How do I
stop
the form from closing?

Just do not assign a 'DialogResult' to the button's 'DialogResult' property
at design time.
 
Back
Top