-
Oct 11th, 2013, 04:48 AM
#1
Thread Starter
Junior Member
-
Oct 11th, 2013, 05:08 AM
#2
Re: VB 6 Picture Box Movement
Code:
Private Sub Command1_Click()
Picture1.Left = Picture1.Left + 50
Picture2.Left = Picture2.Left - 50
End Sub
-
Oct 11th, 2013, 07:46 PM
#3
Thread Starter
Junior Member
Re: VB 6 Picture Box Movement
Thanks, but I've already got that part except I'm using
.Top since I'm moving picturebox up and down. I can code two pictureboxes moving except if you are moving one the other doesn't move. Does anyone know how to solve this?
-
Oct 11th, 2013, 09:06 PM
#4
Hyperactive Member
Re: VB 6 Picture Box Movement
Originally Posted by AdvComp
I can code two pictureboxes moving except if you are moving one the other doesn't move.
Can you explain what do you mean ? what code do you use ?
-
Oct 12th, 2013, 03:43 AM
#5
Frenzied Member
Re: VB 6 Picture Box Movement
Thanks, but I've already got that part except I'm using
.Top since I'm moving picturebox up and down. I can code two pictureboxes moving except if you are moving one the other doesn't move. Does anyone know how to solve this?
try the following way . hope it might help
Code:
Option Explicit
Dim bmove As Boolean
Private Sub btmove_Click()
bmove = True
Picture1.Left = Picture1.Left + 50
End Sub
Private Sub btmovetop_Click()
If bmove = False Then
Picture1.Top = Picture1.Top + 50
End If
End Sub
-
Oct 12th, 2013, 04:21 AM
#6
Re: VB 6 Picture Box Movement
post the movement code here.
I'm taking a long shot guess here, correct me if im wrong, you're using Keypress to move a picture box like this:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then Picture1.Top = Picture1.Top + 50
If KeyCode = vbKeyUp Then Picture1.Top = Picture1.Top - 50
If KeyCode = vbKeyLeft Then Picture1.Left = Picture1.Left - 50
If KeyCode = vbKeyRight Then Picture1.Left = Picture1.Left + 50
End Sub
And this causes you not to be able to move the picture box up and left (diagonally) simultaneously for example.
You may use this code instead:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer ' Auto Typer Keys
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If GetAsyncKeyState(vbKeyDown) Then Picture1.Top = Picture1.Top + 50
If GetAsyncKeyState(vbKeyUp) Then Picture1.Top = Picture1.Top - 50
If GetAsyncKeyState(vbKeyLeft) Then Picture1.Left = Picture1.Left - 50
If GetAsyncKeyState(vbKeyRight) Then Picture1.Left = Picture1.Left + 50
End Sub
do post if that indeed was the issue.
do remember that moving a control over another control \ form, will cause it to flicker.
you may solve that by using Bitbit (i'll elaborate about it if required).
-
Oct 12th, 2013, 11:30 AM
#7
Thread Starter
Junior Member
Re: VB 6 Picture Box Movement
I am coding the game Pong. I have A+Z to go up and down for picture1 and for picture2 I use the arrow keys. Except if I press For example, A and an arrow key, only one of the pictures move
-
Oct 12th, 2013, 11:52 AM
#8
Re: VB 6 Picture Box Movement
A picture is worth a thousand words, if you know what I mean.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
-
Oct 12th, 2013, 12:21 PM
#9
Thread Starter
Junior Member
Re: VB 6 Picture Box Movement
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then Picture1.Top = Picture1.Top + 50
If KeyCode = vbKeyUp Then Picture1.Top = Picture1.Top - 50
If KeyCode = vbKeyZ Then Picture2.Left = Picture2.Left + 50
If KeyCode = vbKeyA Then Picture2.Left = Picture2.Left - 50
End Sub
-
Oct 12th, 2013, 01:01 PM
#10
Re: VB 6 Picture Box Movement
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If GetAsyncKeyState(vbKeyDown) Then Label1.Top = Label1.Top + 50
If GetAsyncKeyState(vbKeyUp) Then Label1.Top = Label1.Top - 50
If GetAsyncKeyState(vbKeyZ) Then Label2.Left = Label2.Left + 50
If GetAsyncKeyState(vbKeyA) Then Label2.Left = Label2.Left - 50
End Sub
This works simultaneously
-
Oct 12th, 2013, 04:28 PM
#11
Thread Starter
Junior Member
Re: VB 6 Picture Box Movement
Originally Posted by stum
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If GetAsyncKeyState(vbKeyDown) Then Label1.Top = Label1.Top + 50
If GetAsyncKeyState(vbKeyUp) Then Label1.Top = Label1.Top - 50
If GetAsyncKeyState(vbKeyZ) Then Label2.Left = Label2.Left + 50
If GetAsyncKeyState(vbKeyA) Then Label2.Left = Label2.Left - 50
End Sub
This works simultaneously
Thanks a lot this works for me. But i am wondering what does the declaration do?
Thanks Again
-
Oct 12th, 2013, 05:44 PM
#12
Hyperactive Member
Re: VB 6 Picture Box Movement
Good, Tag it as resolved
the declaration is to declare the api that you are using to get if the key is pressed or not ! you are calling this function which is not native VB so you should declare it
-
Oct 21st, 2013, 06:32 AM
#13
Thread Starter
Junior Member
Re: VB 6 Picture Box Movement
How do you tag it as resolved?
-
Oct 21st, 2013, 09:03 AM
#14
Re: VB 6 Picture Box Movement
Originally Posted by AdvComp
How do you tag it as resolved?
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
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
|