Solved

Why doesn't Keys.Left work???

Posted on 2006-11-03
4
223 Views
Last Modified: 2010-04-23
Hi guys, ive got a bit of a strange one, If i use the code :


Dim x As Integer
    Dim y As Integer

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        x = x + 10
        y = x + 5

        If Keys.Enter Then
            PictureBox1.Location = New Point(x, y)
        End If


IT WORKS FINE, but when i use

Keys.Left, Keys.Right ... up or down for the arrow keys then it doesnt work?? THis is really strange, could someone please try and help me, thanks very much
0
Comment
Question by:dajoebomb
[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
4 Comments
 

Author Comment

by:dajoebomb
ID: 17867164
ALso i have just noticed some other keys don't work either, page up, right shift key, these a just  a few random examples. Is there another way to do the same thing?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 100 total points
ID: 17867270
Try...

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Left
                PictureBox1.Left = PictureBox1.Left - 10

            Case Keys.Right
                PictureBox1.Left = PictureBox1.Left + 10

            Case Keys.Up
                PictureBox1.Top = PictureBox1.Top - 10

            Case Keys.Down
                PictureBox1.Top = PictureBox1.Top + 10

            Case Keys.PageUp
                PictureBox1.Top = PictureBox1.Top - 25

            Case Keys.PageDown
                PictureBox1.Top = PictureBox1.Top + 25

            Case Keys.Enter
                MsgBox("enter pressed")

        End Select

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
0
 

Author Comment

by:dajoebomb
ID: 17867306
Excellent cheers!
0
 
LVL 8

Expert Comment

by:razo
ID: 17867307
try this
    If e.KeyCode = Keys.enter Then

0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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