Reputation: 7
How do i make a KeyDown event for a Form?
When I have the application open, I want to know when I type certain keys to display a message.
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Enter Then
MsgBox("enter key pressd ")
End If
End Sub
Upvotes: 0
Views: 506
Reputation: 46
Have you taken a look at vb.net Keydown event on whole form?
KeyPreview property should be set to True
on the form.
Code used in answer (not what you want to do exactly):
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
If e.Control AndAlso e.KeyCode = Keys.S then
' Call your sub method here .....
YourSubToCall()
' then prevent the key to reach the current control
e.Handled = False
End If
End Sub
Upvotes: 3