Trapping F10 / WinForms

  • Thread starter Thread starter Amos Soma
  • Start date Start date
A

Amos Soma

I have a WinForm and I'm attempting to trap the F10 key so that I can
perform my own function when it's pressed. I've been unsuccessful in doing
this. It seems no matter what I do, the F10 key causes focus to go to my app
menu. Is there some way I can override the default behavior of F10 and
execute my own method?

Thanks.
 
Hi,

Set the KeyPreview property of the form to True and check for the pressed
key in the keyup (or keydown) event of the form.

Eg:

private void MyForm_KeyUp(object sender, System.Windows.Forms.KeyEventArgs
e)
{
if (e.KeyCode == Keys.F10)
{
// Your action goes here
// Comment the following line if you want the menu to be highlighted
after your logic.
e.Handled = true;
}
}

Hope this helps.

I have a WinForm and I'm attempting to trap the F10 key so that I can
perform my own function when it's pressed. I've been unsuccessful in doing
this. It seems no matter what I do, the F10 key causes focus to go to my app
menu. Is there some way I can override the default behavior of F10 and
execute my own method?

Thanks.
 
Back
Top