Link to home
Start Free TrialLog in
Avatar of JayneBR
JayneBR

asked on

Move a control using the up and down arrows.

 I want to build a PONG game and use the up and down arrows to move the paddles (picturebox with white backcolor sahped like pong paddle with no picture). I have tried the following code with no success. It doesn't seem like an event is being triggered by the Form_Keydown event. What am I missing?

Private Sub Form_KeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer)

      Form1.ActiveForm.KeyPreview = True

      Select Case KeyCode
         Case 38
            pic1.Top -= 10
         Case 40
            pic1.Top += 10
      End Select

   End Sub
ASKER CERTIFIED SOLUTION
Avatar of Jason Evans
Jason Evans
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JayneBR
JayneBR

ASKER

Well, you got me thinking and I changed the signature of the keydown event when I changed the parameters. So I used the forms built-in keydown event and it works as designed. Here is the code:

 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

      Form1.ActiveForm.KeyPreview = True

      Select Case e.KeyCode
         Case 38
            pic1.Top -= 10
         Case 40
            pic1.Top += 10
      End Select

   End Sub