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
Printable View
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
You will need to override the ProcessDialogKey function to capture the arrow keys...
vb Code:
Public Class Form1 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'pass the keydata to the ProcessDialogKey function Dim bln As Boolean = ProcessDialogKey(e.KeyData) End Sub Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean 'move the button, you will need to add code to check for reaching the client bounds Select Case keyData Case Keys.Up Button2.Top -= 2 Case Keys.Down Button2.Top += 2 Case Keys.Left Button2.Left -= 2 Case Keys.Right Button2.Left += 2 End Select Return True End Function End Class
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