Solved

Why doesn't Keys.Left work???

Posted on 2006-11-03
4
186 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
Comment Utility
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
Comment Utility
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
Comment Utility
Excellent cheers!
0
 
LVL 8

Expert Comment

by:razo
Comment Utility
try this
    If e.KeyCode = Keys.enter Then

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

15 Experts available now in Live!

Get 1:1 Help Now