DialogResult and CancelButton

L

Lee Moody

If you specify a CancelButton property on a form to a
specific button, but you specify 'None' as DialogResult
for that button, and you show the form using ShowDialog,
pressing ESCape key is causing the DialogResult to fire
and closes the form.

Is this another potential design flaw or is this on
purpose?

-Lee
 
H

Herfried K. Wagner [MVP]

* "Lee Moody said:
If you specify a CancelButton property on a form to a
specific button, but you specify 'None' as DialogResult
for that button, and you show the form using ShowDialog,
pressing ESCape key is causing the DialogResult to fire
and closes the form.

The button will be fired, but no 'DialogResult' will be set. You can
set the 'DialogResult' in the cancel button's 'Click' event handler.
 
L

Lee Moody

My point is, what you've described is what I would EXPECT
to happen, but that is not happening. The DialogResult IS
being executed. I know, because I set up code in the
CancelButton assigned button such that, I execute the
DialogResult under certain circumstances and sometimes I
don't but the form kept closing regardless. I had to get
to the point of setting the form to perform KeyPreview to
True of the Form, and removing the CancelButton assignment
and to issue the test/closing of form within the KeyPress
event of the Form whenever the user pressed ESCape.

-Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top