I'm experiencing some troubles using mnemonic keys in Windows Forms:
Simply having a form with a button, which uses ALT+s as the accelerator:
this.searchButton = new System.Windows.Forms.Button();
this.searchButton.Text = "&search";
The button action is executed by simply pressing "s" (without pressing the ALT key). I have checked some other applications, and the accelerator actions are only executed when the ALT key is pressed.
Thanks in advance.
You can alter this behavior by pasting this snippet into your form:
protected override bool ProcessDialogChar(char charCode) {
if ((Control.ModifierKeys & Keys.Alt) == Keys.None) return false;
return base.ProcessDialogChar(charCode);
}
Not 100% sure this won't have other side-effects, keyboard handling in Winforms is convoluted to put it mildly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With