Capture combination key event in a Windows Forms application

后端 未结 3 1924
南旧
南旧 2020-12-10 13:31

When the user presses the Shift + UP keys, I want my form to respond by calling up a message box.

How do I do this in Windows Forms?

3条回答
  •  一整个雨季
    2020-12-10 14:12

    Handle the KeyDown event and have something like:

    if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.Up)
    {
        MessageBox.Show("My message");
    }
    

    The event handler has to be on the Main Form and you need to set the KeyPreview property to true. This can be done in design mode from the properties dialog.

提交回复
热议问题