|
-
Jul 28th, 2007, 03:38 AM
#1
Thread Starter
Hyperactive Member
keypress
I want to move a button with keypress left/right arrow but this fails?
Code:
If e.KeyCode = Keys.Left Then
Button2.Left -= 5
ElseIf e.KeyCode = Keys.Right Then
Button2.Left += 5
End If
-
Jul 28th, 2007, 05:01 AM
#2
Hyperactive Member
Re: keypress
You will need to override the ProcessDialogKey function to capture the arrow keys...
vb Code:
Public Class Form1
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'pass the keydata to the ProcessDialogKey function
Dim bln As Boolean = ProcessDialogKey(e.KeyData)
End Sub
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
'move the button, you will need to add code to check for reaching the client bounds
Select Case keyData
Case Keys.Up
Button2.Top -= 2
Case Keys.Down
Button2.Top += 2
Case Keys.Left
Button2.Left -= 2
Case Keys.Right
Button2.Left += 2
End Select
Return True
End Function
End Class
If my post helps , please feel free to rate it 
-
Jul 28th, 2007, 05:11 AM
#3
Thread Starter
Hyperactive Member
Re: keypress
Hi,
It works well.
What is the difference between keydown and keypress event?
OK is there another way to get keypresses other than key event e?
I see some code use acii value and some use Vbcr for enter key
Last edited by jagguy; Jul 28th, 2007 at 05:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|