C#:如何在文本框中按Enter触发按钮,但仍然允许快捷键(例如"Ctrl + A")通过,渡过?

问题描述:

很抱歉,标题太长了,但我想不出另一种方式来写.

Sorry for the long title, but I couldn't think of another way to put it.

我有这个:

    private void textBoxToSubmit_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            buttonSubmit_Click((object)sender, (EventArgs)e);
        }
    }

...为了使在文本框中按Enter触发提交"按钮.但是,这也会阻止快捷方式通过. (不太确定这与它有什么关系,也许只是多键组合?)

... in order to make pressing enter in the text box trigger the "submit" button. However, this also prevents shortcuts from going through. (not quite sure what it has to do with that, maybe only multi-key combos?)

ShortcutsEnabled设置为true.

ShortcutsEnabled is set to true.

提前谢谢!

您不能在Forms Properties Window中使用AcceptButton吗?这将设置 Enter 按键的默认行为,但是您仍然可以使用其他快捷方式.

Can you not use AcceptButton in for the Forms Properties Window? This sets the default behaviour for the Enter key press, but you are still able to use other shortcuts.