How to set hotkeys for a Windows Forms form

后端 未结 8 1690
孤街浪徒
孤街浪徒 2020-12-03 05:22

I would like to set hotkeys in my Windows Forms form. For example, Ctrl + N for a new form and Ctrl + S for save. How would I do

相关标签:
8条回答
  • 2020-12-03 06:05

    You can set it using a hidden menu too, if you want. Just set the property of menu.visible = false;

    0 讨论(0)
  • 2020-12-03 06:06

    First, you need to handle the KeyDown event, and then you can start watching out for your modifiers:

    private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        if (Control.ModifierKeys == Keys.Control && e.KeyCode == Keys.S)
        {
            //Do whatever
        }
    }
    

    Of course, you need to make sure your form subscribes to the KeyDown event.

    0 讨论(0)
提交回复
热议问题