I would like to set the focus onto a control when the user presses Alt+D. However, Alt+D sets the focus on the first item in the menustrip after setting the focus in the keydown event handler.
Setting the form KeyPreview to True and e.Handled to true when the Alt key is pressed has no effect.
D is an arbitrary key for this example -- it happens on all alpha keys.
I'm using vb.net 2008.
Sample code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt And e.KeyCode = Keys.D Then
Button1.Focus()
e.Handled = True
End If
End Sub
Sample form, after pressing Alt+D. Focus was on Button2 before pressing Alt+D.