?
Solved

Why doesn't Keys.Left work???

Posted on 2006-11-03
4
Medium Priority
?
226 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 400 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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