多键按下 [英] multi keys in key down

查看:79
本文介绍了多键按下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望当我按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:

  1. 将keyEventArgs属性ModifierKey.Control(与您在示例中一样,不是 Keys.ControlKey)进行比较.


  1. Compare the keyEventArgs property Modifier against Key.Control (not Keys.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;
    }

}


  • 如果您可以使用 ALT + S 作为快捷方式,则可以将CheckBox控件的Text属性设置为"Check& Search"之类的内容. br/>


  • If you can live with the short cut being ALT + S you can set the 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆