Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using keyboard input to move picture box

Posted on 2006-11-10
1
Medium Priority
?
453 Views
Last Modified: 2013-12-26
I am trying to write code to move a picture box by pressing the left, right, up or down arrows .

I have tried the following code:

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        Label1.Text = e.KeyChar
        If e.KeyChar = "a" Then
            pb1.Left = 100
        End If

    End Sub

This works if I use "A" on the keyboard or program it for any other letter but does not work for up, down, left and right arrows. There does not seem to be a value in e.keyChar. What would be the easiest code to move the picture box using these keys?

thanks
Max
0
Comment
Question by:maxgall
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17913269
you need to use the keyDown event instead of the Keypress event:

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        if e.KeyCode = Keys.Left then
           pb1.left = 100
        end if
    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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

782 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