How to assign a shortcut key (something like Ctrl+F) to a text box in Windows Forms?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 . How do I do this? 回答1: 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(); } } 回答2: One way is to override the ProcessCMDKey event. protected override bool ProcessCmdKey