Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to detect arrow keys in vb.net using if statement?
Posted

1 solution

check keycode for the keypressed.Use case statements here's the sample

VB
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    ' Sets Handled to true to prevent other controls from
    ' receiving the key if an arrow key was pressed
    Dim bHandled As Boolean = False
    Select Case e.KeyCode
        Case Keys.Right
            'do stuff
            e.Handled = True
        Case Keys.Left
            'do other stuff
            e.Handled = True
        Case Keys.Up
            'do more stuff
            e.Handled = True
        Case Keys.Down
            'do more stuff
            e.Handled = True
    End Select
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900