Dear all,
WinForms 10.3: we have modal form called with
.....form.ShowDialog() == DialogResult.Ok;
and the form contains UltraButton instances for Ok and Cancel. For some strange reason, pressing ESC was not closing the form when the Cancel button was set to the CancelButton property of the form. So my developer played around and found that if AcceptsFocus is set to true for the Cancel button, the ESC keypress closed the window, but not if AcceptsFocus is set to false.
The reason for disabling this that we do not want to have the focus border around the cancel button immediatley after startup (prevent the thick border there).
But even if we have to just make a workaround and manually shift the focus upon activation, shouldn´t be the ESC button bound in any way to the CancelButton property in such a way that it does not need to have the focus?
Thanks and regards Florian
Mike,
ok we can accept this. The form behaviour does not really change if we leave the AcceptsFocus enabled. Thanks
Florian
Hi Florian,
I apologize for using the phrase "Confirmed as a bug." Our engineers have looked into this, and determined that it is intended behavior.
The reason that the AcceptsFocus property blocks the ESC key binding is that turning AcceptsFocus off sets the button's ControlStyle to non-selectable. The same result can be achieved by deriving a class from Button and setting its ControlStyle to non-selectable.
Please let me know if you have any further questions.
Hello Florian,
We have confirmed that this is a bug and we have logged it in our system. The issue number is 66459.
Dear Mike,
thanks for your reply. Yes we have tried your suggestions, in fact I think you mean to use the TabIndex property for this. You are right that disabling the indication may be not what we want.
Still we would like to know why AcceptsFocus blocks the accelerator key binding for the ESC key. Thanks for looking into this.
regards Florian
When a form is shown, focus is automatically given to a control based on the TabStop property. It may be a simpler workaround to change the TabStop property of your OK button so that it is a smaller value than the TabStop property of the Cancel button.
It is possible to disable the thick blue border around the button by setting the button's ShowOutline property to false. You can also disable the focus rectangle by setting the button's ShowFocusRect property to false. Note that if you disable both properties, the user will have no indication that the button has focus, and may become confused.
I will follow up with you on the cancel button functionality.