如何在我的应用程序中使用键盘左右箭头键 [英] How to use keyboard right and left arrow keys in my application
本文介绍了如何在我的应用程序中使用键盘左右箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在应用程序中使用键盘的左右箭头键,而不是单击
是或否按钮
How can i use the keyboard right and left arrow keys in my application instead of click the
yes or no buttons
推荐答案
KeyDown
事件,如此处所述
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx [ ^ ]
可用于此目的.
要在传递给表单上的任何控件之前捕获按下的键,
可以将KeyPreview
的KeyPreview
属性设置为True
,这表示在将事件传递给具有焦点的控件之前,窗体将接收键事件,如此处所述
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx [ ^ ]
TheKeyDown
event as explained here
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx[^]
can be used for this purpose.
To capture the key pressed before it is passed on to any control on the form,
KeyPreview
property ofForm
can be set toTrue
, which indicates that the form will receive key events before the event is passed to the control that has focus as explained here
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx[^]
嘿,
试试这个
hey,
try this
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Left) {
Console.WriteLine("left");
return true;
}
// etc..
return base.ProcessCmdKey(ref msg, keyData);
}
祝你好运
Best Luck
这篇关于如何在我的应用程序中使用键盘左右箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文