Closed Serg-Norseman closed 11 months ago
What platform(s) have you tried? If it's only certain platforms I may want to make this more consistent.. e.g. space to select the button with focus, enter to always press the default button.
In the meantime, you could handle the KeyDown event on each of the buttons to intercept the enter key. e.g..
myDialog.Styles.Add<Button>(null, b => {
b.KeyDown += (sender, e) => {
if (e.KeyData == Keys.Enter)
{
myDialog.DefaultButton?.PerformClick();
e.Handled = true;
}
};
});
Your solution suits me, it works as it should. The issue can be closed.
It's not a big problem. Just a minor inconvenience.
There are many dialogues. Each dialog has an assigned DefaultButton. If, while working in the dialog, the user has focus on one of the other buttons (not the DefaultButton) and does not notice this and presses Enter in order to execute "apply" - the button under focus is clicked.
Is there a way to intercept all button presses in the dialog, and if the assignment control is not DefaultButton, then block the transfer of Enter?
Or maybe there is a way to exclude the possibility of getting focus for all buttons in dialogs except DefaultButton and AbortButton?