从选择menuStrip禁用Alt热键

时间:2013-10-12 05:21:08

标签: c#

所以我为alt和其他按钮设置了快捷方式,以便将文本插入textbox。但每当我点击alt时,它会选择我的menuStrip并选择一个menuItem,其中的字母最接近键盘按下的字母。

我试过了:

if (e.KeyCode == Keys.Alt)
{
    handled = true;
}

this tutorial所示,但它会抛出一个错误,说处理不存在。

2 个答案:

答案 0 :(得分:3)

Control_KeyDown(object sender, KeyEventArgs e) 
    {
     if (e.Alt)
       {
            e.Handled = false;
       }
    }

尝试使用KeyDown事件。

答案 1 :(得分:0)

首先处理KeyDown事件:

        KeyDown += MainWindow_KeyDown;

在此事件处理程序中,当按下其中一个ALT键时,将第二个参数的Handled属性设置为true。

    void MainWindow_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.System && (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt))
        {
            e.Handled = true;
        }
    }
相关问题