Solved

Move a control using the up and down arrows.

Posted on 2006-11-18
2
194 Views
Last Modified: 2010-04-23
 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
0
Comment
Question by:JayneBR
2 Comments
 
LVL 10

Accepted Solution

by:
MrClyfar earned 500 total points
ID: 17972655
Hi there.

Your better off using the KeyPress event of the Form, rather then KeyDown. Try experimenting with it to see how it goes for you.

Jas.
0
 

Author Comment

by:JayneBR
ID: 17972756
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question