Solved

Why doesn't Keys.Left work???

Posted on 2006-11-03
4
197 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
  • 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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now