SolvedMoving PictureBox Through Keystrokes

Posts 1–2 of 2 · Page 1 of 1
Moving PictureBox Through Keystrokes
hey guys,

I have a picture box that i want to move via the arrow keys, and when its pressed and/or held down it will move
here is my current code :


Private Sub PictureBox18_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Up Then
PictureBox18.Top -= 10
ElseIf e.KeyCode = Keys.Down Then
PictureBox18.Top += 10
ElseIf e.KeyCode = Keys.Left Then
PictureBox18.Left -= 10
ElseIf e.KeyCode = Keys.Right Then
PictureBox18.Left += 10
End If
End Sub

Would appreciate some help, and i apologies if its a noob question
Set the "KeyPreview" property of your form to "True". Either through the IDE or in your form_load event put:

Code:
Me.KeyPreview = True
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us