Solved

Why doesn't Keys.Left work???

Posted on 2006-11-03
4
213 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML - Color not displaying correctly in EMAIL. 6 49
export data table to excel in vb.net 10 36
Optimize the query 5 43
Convert Ctime to date time in textfile? 7 32
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…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

837 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