Results 1 to 2 of 2

Thread: How do I link code to arrow keys in VB.NET?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    9

    How do I link code to arrow keys in VB.NET?

    Hello there

    I'm trying to write code which responds to the users manipulation of 2 of the arrow keys (you know the ones just under the delete, end and page down keys). The code below compiles okay but it doesn't do anything. I just was just wondering how to modify it.
    All contributions gratefully accepted.

    meandmymachine


    Heres the code:

    Dim vbKeyRight As Integer
    Dim vbKeyLeft As Integer

    Private Sub KeyPress1_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
    If KeyCode = vbKeyRight Then
    MsgBox("Right Key Pressed!")
    End If
    End Sub

    Private Sub KeyPress2_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)
    If KeyCode = vbKeyLeft Then
    MsgBox("Left Key Pressed!")
    End If
    End Sub

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Simply change it to this :
    VB Code:
    1. Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e
    2. As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    3.         If e.KeyCode = Keys.Right Then
    4.             MsgBox("Right Key Pressed!")
    5.         End If
    6.  End Sub
    7.  
    8. Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e
    9. As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
    10.         If e.KeyCode = Keys.Left Then
    11.             MsgBox("Left Key Pressed!")
    12.         End If
    13.     End Sub

    I don't know why you declared two variables ? It could work if you just assigned them the ascii codes for left & right keys .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width