Reputation: 5968
.NET : I have a Context menu strip that I want to handle using keyboard keys.
I have the following event handler:
Private Sub ContextMenuEnterKey(ByVal Sender As Object, ByVal E As KeyEventArgs) Handles ContextMenu.KeyDown
If E.KeyValue = Keys.Enter Then
'Do some staff
End If
End Sub
The events fires correctly with other keys except EnterKey.
Does anyone know what's wrong with that ?
Upvotes: 2
Views: 1325
Reputation: 29164
To which control's KeyDown
event are you binding your handler? In the Forms designer the ? KeyDown
event isn't even shown for ContextMenuStrip
(at least here in VS2012, and I'm working in C#...) I can bind to in in code, but this doesn't seem to have any effect.
But there is a PreviewKeyDown
event in ContextMenuStrip
which gets called for every keystroke within the context menu, also for the Enter key. Maybe this can help you?
Upvotes: 3