?
Solved

Move a control using the up and down arrows.

Posted on 2006-11-18
2
Medium Priority
?
197 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:
Jason Evans earned 1500 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

Technology Partners: 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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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