Keyboard shortcut for a button

后端 未结 3 1506
情话喂你
情话喂你 2020-12-31 02:59

In C# (Microsoft Visual Studio 2010), how can I assign a keyboard shortcut to a button such as the following?

    private void closeButton_Click(ob         


        
3条回答
  •  悲&欢浪女
    2020-12-31 03:36

    if you want add Ctrl + S in switch statment so you can also try below code.

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case Keys.Control | Keys.S:
                    // do something...
                    return true;
                case Keys.Control |Keys.Alt | Keys.S:
                    // do something...
                    return true;
                case Keys.F2:
                    // do something...
                    return true;
                case Keys.F3:
                    // do something...
                    return true;
                case Keys.F4:
                    // do something...
                    return true;
                default:
                    return base.ProcessCmdKey(ref msg, keyData);
            }
        }
    

提交回复
热议问题