Accelerator (mnemonic key) is executed without pressing the ALT key

I am having some problems using mnemonic keys in Windows Forms :

Just having a form with a button that uses ALT + s as an accelerator:

this.searchButton = new System.Windows.Forms.Button();
this.searchButton.Text = "&search";

The button action is performed by simply pressing "s" (without pressing the ALT key). I checked some other applications, and accelerator actions are only performed when the ALT key is pressed.

  • Is this a .NET problem?
  • How to solve this problem?

Thanks in advance.

+5
source share
2 answers

This is normal behavior for .NET ("by design," they say).

, - , , , , :

.NET Windows Forms Applications - Code Guru

, , - ProcessCmdKey .

+2

, :

    protected override bool ProcessDialogChar(char charCode) {
        if ((Control.ModifierKeys & Keys.Alt) == Keys.None) return false;
        return base.ProcessDialogChar(charCode);
    }

, 100% , Winforms , .

+5

All Articles