I have a modal Form with three Buttons, A B and C.
In addition, I have two Buttons: OK
and Cancel
. The OK
Button's DialogResult
property is set to DialogResult.OK
and the Cancel
Button DialogResult.Cancel
.
The Form's AcceptButton
and CancelButton
properties are set to these Buttons.
Currently, the Form is closed when I press the ESC
key but if I click the ENTER
key when one of the other Buttons (A,B,C) is the Active Control, the Form is not closed. How can I overcome this?
I have two options:
Enter will always close the form (select the focused button and then close it),
The first Enter key press will select the focused button and a second
ENTER
press will close the Form. The problem is that maybe ButtonA
was selected but the user can go over ButtonB
orC
using the arrow keys.
I can't set a DialogResult.OK
to the other Buttons, because - in that case - a normal click will also close the Form and I have no way to detect if the event was called because of a Click event or the ENTER
key...