954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Making keystrokes move a picture box?

I'm sure there is a simple way to make a keystrok such as the up arrow adjust the location of the picture box, however I don't know how to tell the program to perhaps

picturebox1.location = picturebox1.location + 1


when a key is pressed...

help please!

mark192
Newbie Poster
18 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Actually scratch that, I really just want to know how I would say....

make a text box say "Left Key Pressed!" when i push the left key?

mark192
Newbie Poster
18 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

handle it with keyDown Event.
this following code is form keydown event, you can do same with other controls.

Private Sub Search_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Up Then
            'PictureBox1.Top -= 10
            MsgBox("Key Up Pressed")
        ElseIf e.KeyCode = Keys.Down Then
            'PictureBox1.Top += 10
            MsgBox("Key Top Pressed")
        ElseIf e.KeyCode = Keys.Left Then
            'PictureBox1.Left -= 10
            MsgBox("Key Left Pressed")
        ElseIf e.KeyCode = Keys.Right Then
            'PictureBox1.Left += 10
            MsgBox("Key Right Pressed")
        End If
    End Sub
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You