如何分配在Windows窗体快捷键(像按Ctrl + F)到一个文本框?

问题描述:

我建立使用C#的工具。这是一个Windows应用程序。我有一个表格上的一个文本框,我要分配焦点设置到文本框,当用户按下控制骨节病> + ˚F骨节病>或控制骨节病> + 取值骨节病>。

I am building a tool using C#. It's a Windows application. I have one text box on a form, and I want to assign focus to that text box when the user presses Ctrl + F or Ctrl + S.

我如何做到这一点?

的KeyDown 事件和地点的,如果它的语句来检查被按什么键。

Capture the KeyDown event and place an if statement in it to check what keys were pressed.

private void form_KeyDown(object sender, KeyEventArgs e)
{
    if ((e.Control && e.KeyCode == Keys.F) || (e.Control && e.KeyCode == Keys.S)) {
        txtSearch.Focus();
    }
}