picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.55k stars 323 forks source link

Is there a way to block button click handler calls in dialogs when they have focus and the user presses Enter? #2516

Closed Serg-Norseman closed 11 months ago

Serg-Norseman commented 1 year ago

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?

cwensley commented 1 year 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;
    }
  };
});
Serg-Norseman commented 11 months ago

Your solution suits me, it works as it should. The issue can be closed.