Not a Member Yet,
Click here to Register
How do you like the new design?






ID: 341
Viewed: 2861
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

I'll assume that you want to move the form

Don't forget to set the KeyPreview property to TRUE.


to move something else instead of the form-
In that case the code is same as before, just instead of ME keyword put the name of the object you want to move.

Highlight all by clicking in box
<!---Declaration--->
none

Highlight All
<!---Code--->
'code:---------------------------------------------------

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp
Me.Top = Me.Top - 120
Case vbKeyDown
Me.Top = Me.Top + 120
Case vbKeyLeft
Me.Left = Me.Left - 120
Case vbKeyRight
Me.Left = Me.Left + 120
End Select
End Sub


'to make it a smooth move

Dim blnMove As Boolean ' indicates wheter to move the object or not

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
blnMove = True ' set to move the object
Do
Select Case KeyCode
Case vbKeyUp
Me.Top = Me.Top - 20
Case vbKeyDown
Me.Top = Me.Top + 20
Case vbKeyLeft
Me.Left = Me.Left - 20
Case vbKeyRight
Me.Left = Me.Left + 20
End Select
DoEvents ' let the system handle other things
Loop While blnMove ' loop while the value of blnMove = TRUE
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
blnMove = False ' set not to move the object
End Sub

'This code will move the form around the screen (smoothly) 'until you release any key. To make the object moves more 'smoothly, try decreasing the numeric values (I put 20 'instead of 120 this time).


'You can use the loop statement in two ways:


'1. Loop Until Not blnMove (same as Loop Until blnMove = False)
'2. Loop While blnMove (same as Loop While blnMove = True)
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 snippetlibrary.com All Rights Reserved. Conditions