tags:

views:

20

answers:

1

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

How to do this in Windows Form?

+1  A: 

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.

ChrisF
Don't think it works. I tried a lot of times, but the MessageBox never come up
Ngu Soon Hui
@Ngu Soon Hui - can you post your code then. It should work.
ChrisF
@ChrisF, it does work on a `keydown` event for a form. Sorry. I was putting the above code in the `keydown` event of the control hosted in the form, which was why it didn't work
Ngu Soon Hui