Search This Blog

Monday, June 3, 2013

Arrow keys not trigger VB NET

VB.NET > Form > Methods > ProcessCmdKey

ProcessCmdKey method processes a command key.

Example:
Use ProcessCmdKey to catch arrow keys (arrow keys not trigger VB NET in form events)

Solution:
   
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keydata As Keys) As Boolean
        If keydata = Keys.Right Or keydata = Keys.Left Or keydata = Keys.Up Or keydata = Keys.Down Then
            OnKeyDown(New KeyEventArgs(keydata))
            ProcessCmdKey = True
        Else
            ProcessCmdKey = MyBase.ProcessCmdKey(msg, keydata)
        End If
    End Function

Private Sub RunForm_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Right Then
        End If
End Sub