Results 1 to 3 of 3

Thread: keypress

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    keypress

    I want to move a button with keypress left/right arrow but this fails?
    Code:
      If e.KeyCode = Keys.Left Then
                Button2.Left -= 5
            ElseIf e.KeyCode = Keys.Right Then
                Button2.Left += 5
            End If

  2. #2
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: keypress

    You will need to override the ProcessDialogKey function to capture the arrow keys...

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
    4.         'pass the keydata to the ProcessDialogKey function
    5.         Dim bln As Boolean = ProcessDialogKey(e.KeyData)
    6.     End Sub
    7.  
    8.  
    9.     Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
    10.         'move the button, you will need to add code to check for reaching the client bounds
    11.         Select Case keyData
    12.             Case Keys.Up
    13.                 Button2.Top -= 2
    14.             Case Keys.Down
    15.                 Button2.Top += 2
    16.             Case Keys.Left
    17.                 Button2.Left -= 2
    18.             Case Keys.Right
    19.                 Button2.Left += 2
    20.         End Select
    21.  
    22.         Return True
    23.     End Function
    24.  
    25. End Class
    If my post helps , please feel free to rate it

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    439

    Re: keypress

    Hi,

    It works well.

    What is the difference between keydown and keypress event?


    OK is there another way to get keypresses other than key event e?
    I see some code use acii value and some use Vbcr for enter key
    Last edited by jagguy; Jul 28th, 2007 at 05:17 AM.

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