e.Handled and F10

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

Amos Soma

In my Win form, I have KeyPreview set to True. In my form KeyUp method, I
have the following code:

if (e.KeyCode == Keys.F10)
{
e.Handled = true;
MessageBox.Show( "F10 pressed" );
}

The message is displayed correctly. However, focus moves off my form and
unto my menu, even though I have e.Handled set to true. How can I prevent
this from happening?

Thanks.
 
Amos Soma said:
In my Win form, I have KeyPreview set to True.
In my form KeyUp method, I have the following
code:
[...]
The message is displayed correctly. However, focus
moves off my form and unto my menu, even though
I have e.Handled set to true.

What operating system are you using? I can't reproduce this on Windows
XP Professional. Whether KeyPreview is true or false, F10 only goes to
the menu if I do *not* set e.Handled = true.

Anyway, my first suggestion is not to use F10, because it's a standard
Windows shortcut for going to the menu bar. It's a bit like assigning
your own special meaning to the Start key - it will no longer perform
its proper function.

Otherwise, I suppose you'll have to do something messy like
temporarily disabling the menus in your KeyUp handler and re-enabling
them afterwards.

P.
 
Back
Top