C#:如何在文本框中按Enter触发按钮,但仍然允许快捷键(例如"Ctrl + A")通过,渡过? [英] C#: How to make pressing enter in a text box trigger a button, yet still allow shortcuts such as "Ctrl+A" to get through?

查看:381
本文介绍了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.

这篇关于C#:如何在文本框中按Enter触发按钮,但仍然允许快捷键(例如"Ctrl + A")通过,渡过?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆