Solved

Move a control using the up and down arrows.

Posted on 2006-11-18
2
190 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now