English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I would like it to move a a pixel or two each time. I understand I need to use vbKeyUp, vbKeyDown, vbKeyLeft, vbKeyRight, but I don't understand how I am supposed to write the code. Say I am using Shape1 as the object I would like to move. What code do I have to write? Under what private sub? I need to introduce Keycode as integer? Why?

2007-12-04 15:18:18 · 1 answers · asked by Dido 4 in Computers & Internet Programming & Design

1 answers

Hi,
Put a shape on the form and write the following code:
----------------------------------------------------------------------
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'for going left and right
If KeyCode = 37 Then Shape1.Left = Shape1.Left - 10
If KeyCode = 39 Then Shape1.Left = Shape1.Left + 10

'for going up and down
If KeyCode = 38 Then Shape1.Top = Shape1.Top - 10
If KeyCode = 40 Then Shape1.Top = Shape1.Top + 10
End Sub
-------------------------------------------------------------------------------

2007-12-04 19:33:09 · answer #1 · answered by iqbal 4 · 0 0

fedest.com, questions and answers