按钮的键盘快捷键
在 C# (Microsoft Visual Studio 2010) 中,如何为像下面这样的按钮?
private void closeButton_Click(object sender, EventArgs e)
{
// Close the program
this.Close();
}
我知道我可以使用“&”按钮文本中的字符并创建一个 Alt - n 快捷方式,但我想创建一个按键快捷方式,例如 c 来执行上面的操作。
In C# (Microsoft Visual Studio 2010), how can I assign a keyboard shortcut to a button such as the following?
private void closeButton_Click(object sender, EventArgs e)
{
// Close the program
this.Close();
}
I know I can use the "&" character in the button's Text and create an Alt - n shortcut, but I'd like to create a single keypress shortcut, such as c to execute the above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
KeyDown 是你的朋友;)例如,如果你想要在按下 Shift 时使用快捷键 A,请尝试以下操作:
如果你想要一个“真正的”键盘快捷键,你可以使用钩子。
查看 Stack Overflow 问题RegisterHotKeys 和全局键盘挂钩? 。
KeyDown is your friend ;) For example, if you want the shortcut key A while Shift is pressed, try this:
If you want a "real" keyboard shortcut you can use hooks.
Look at Stack Overflow question RegisterHotKeys and global keyboard hooks?.
这是一种不同的方法:
您不需要更改
KeyPreview
值。Here's a different approach:
You don't need to change
KeyPreview
value.如果你想在 switch 语句中添加 Ctrl + S ,那么你也可以尝试下面的代码。
if you want add Ctrl + S in switch statment so you can also try below code.