且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多键按下

更新时间:2023-12-03 09:59:34

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