多键按下 [英] multi keys in key down
本文介绍了多键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望当我按Ctrl + S时,我的复选框处于选中状态或未选中状态
但是当我只是按下Ctrl键并且在按下S键之前,会触发KeyDown事件
我希望该按下事件应在Ctrl上触发而不是在Ctrl上触发S
这是代码!!
I want that when i press Ctrl + S then my check box is checked or unchecked
but when I just Press Ctrl key and before pressing S key KeyDown event is fired
i want that key down event should fired on Ctrl an S Not on Just Ctrl
Here is The Code!!
private void frlLOOKUP_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.ControlKey && e.KeyCode == Keys.S)
{
if (check_search.Checked)
{
check_search.Checked = false;
}
else
{
check_search.Checked = true;
}
}
}
推荐答案
private void FormMain_KeyDown(object sender, KeyEventArgs e)
{
if ((e.KeyCode == Keys.S) && (e.Modifiers == Keys.Control))
checkBoxAck.Checked = !checkBoxAck.Checked;
}
确保将窗体的KeyPreview设置为true.
问候
Make sure that KeyPreview of the form is set to true.
Regards
有两个选项供您选择:
There are two options for you:
- 将keyEventArgs属性
Modifier
与Key.Control
(与您在示例中一样,不是Keys.ControlKey
)进行比较.
- Compare the keyEventArgs property
Modifier
againstKey.Control
(notKeys.ControlKey
as you did in your sample).
private void frlLOOKUP_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S)
{
check_search.Checked = !check_search.Checked;
}
}
CheckBox
控件的Text
属性设置为"Check& Search"之类的内容. br/>
Text
property of your CheckBox
control to something like "Check&Search".check_search.Text = "Check&Search";
这将允许您通过按 ALT + S 切换复选框.
This will allow you to toggle the CheckBox by pressing ALT + S.
问候,
曼弗雷德(Manfred)
Regards,
Manfred
这篇关于多键按下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文