Solved

Move a control using the up and down arrows.

Posted on 2006-11-18
2
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 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