|
-
Aug 6th, 2012, 09:06 AM
#1
Thread Starter
PowerPoster
best way to float and move randomly a picture on top of a vb6 form
i am trying to determine how to float move randomly a picture on top of a form. should i use a picturebox or another borderless form or maybe even a child form. Once i determine the best way I will post another question on how to randomly move it and keep it within the boundaries of the form it is over
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 6th, 2012, 09:41 AM
#2
Re: best way to float and move randomly a picture on top of a vb6 form
Use a Picturebox or an Image Control
Code:
Dim nX As Single
Dim nY As Single
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
nX = X / Screen.TwipsPerPixelX
nY = Y / Screen.TwipsPerPixelY
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Image1.Move Image1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Image1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
End If
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
nX = X / Screen.TwipsPerPixelX
nY = Y / Screen.TwipsPerPixelY
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.Move Picture1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Picture1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
End If
End Sub
NOTE: If your Picturebox has it's ScaleMode = vbPixels then don't use the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY
Last edited by jmsrickland; Aug 6th, 2012 at 09:46 AM.
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.
-
Aug 6th, 2012, 09:56 AM
#3
Thread Starter
PowerPoster
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by jmsrickland
Use a Picturebox or an Image Control
Code:
Dim nX As Single
Dim nY As Single
Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
nX = X / Screen.TwipsPerPixelX
nY = Y / Screen.TwipsPerPixelY
End Sub
Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Image1.Move Image1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Image1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
End If
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
nX = X / Screen.TwipsPerPixelX
nY = Y / Screen.TwipsPerPixelY
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1.Move Picture1.Left + ((X / Screen.TwipsPerPixelX)) - nX, Picture1.Top + ((Y / Screen.TwipsPerPixelY)) - nY
End If
End Sub
NOTE: If your Picturebox has it's ScaleMode = vbPixels then don't use the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY
Thanks for adding that, but this has nothing to do with the mouse and i don't think an image control will float on top of other controls, only a picturebox
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 6th, 2012, 10:03 AM
#4
Re: best way to float and move randomly a picture on top of a vb6 form
I'm sorry, I thought you wanted to move a picture on top of a VB6 Form using a mouse.
So, you want to move the picture using code to move picture here and there over other objects on a Form. Without going into code then you need to do a random number selection for X and Y of the picture and make sure that these values keep the picture within the borders of the Form. Is this correct?
Question:
Do you want the picture to show without showing the container box it's in, like moving a ball around the Form?
Last edited by jmsrickland; Aug 6th, 2012 at 10:50 AM.
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.
-
Aug 6th, 2012, 10:51 AM
#5
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by isnoend07
Thanks for adding that, but this has nothing to do with the mouse and i don't think an image control will float on top of other controls, only a picturebox
Correct, but you can simulate an Image control if you use a User Control that has a transparent image on it.
Last edited by jmsrickland; Aug 6th, 2012 at 11:01 AM.
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.
-
Aug 6th, 2012, 02:20 PM
#6
Thread Starter
PowerPoster
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by jmsrickland
I'm sorry, I thought you wanted to move a picture on top of a VB6 Form using a mouse.
So, you want to move the picture using code to move picture here and there over other objects on a Form. Without going into code then you need to do a random number selection for X and Y of the picture and make sure that these values keep the picture within the borders of the Form. Is this correct?
Yes that is correct
Question:
Do you want the picture to show without showing the container box it's in, like moving a ball around the Form?
yes this is a Keno game jackpot, trying to duplicate how the ones at the casino works. have not made the image yet. Wanted to see if and how it works
first
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 10th, 2012, 01:34 PM
#7
Re: best way to float and move randomly a picture on top of a vb6 form
Maybe you could look up on the net about how to make a sprite program.
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.
-
Aug 10th, 2012, 01:51 PM
#8
Thread Starter
PowerPoster
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by jmsrickland
Maybe you could look up on the net about how to make a sprite program.
Thanks I will try
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 11th, 2012, 01:48 AM
#9
Re: best way to float and move randomly a picture on top of a vb6 form
You need to use a PictureBox, it has it's own window and you can also control it's Zorder (Front/Back). About how to move he picturebox with the mouse, it's as easy as:
Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lx As Single, ly As Single
If Button = 0 Then
lx = X
ly = Y
ElseIf Button = vbLeftButton Then
Picture1.Left = Picture1.Left + X - lx
Picture1.Top = Picture1.Top + Y - ly
End If
End Sub
Explanation on the code: If we would set Left and Top values to be X and Y parameters then we would always be dragging the PictureBox by holding its Top-Left corner, so this code first gets the distance between Left/Top PictureBox borders and the X/Y coordinates where the mouse moves (before dragging start), so having this offsets, when dragging starts by holding left mouse button down we can substract them from Left and Top to be able to drag the control by taking it from the real spot where the user clicked inside the PictureBox. Static variables are perfect for doing this since they always retain the value they had the last time the Sub/Function executed, keeping this value even when the Sub/Function where they are declared lose scope. Using modular declared variables for doing this would be exactly the same thing.
EDIT: I see you'll also need transparency, then a PictureBox may not be enough for that, you could use other sort of control like the controls Lavolpe's submitted to the CodeBank.
Last edited by jcis; Aug 11th, 2012 at 02:04 AM.
-
Aug 11th, 2012, 02:40 AM
#10
Thread Starter
PowerPoster
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by jcis
You need to use a PictureBox, it has it's own window and you can also control it's Zorder (Front/Back). About how to move he picturebox with the mouse, it's as easy as:
Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static lx As Single, ly As Single
If Button = 0 Then
lx = X
ly = Y
ElseIf Button = vbLeftButton Then
Picture1.Left = Picture1.Left + X - lx
Picture1.Top = Picture1.Top + Y - ly
End If
End Sub
Explanation on the code: If we would set Left and Top values to be X and Y parameters then we would always be dragging the PictureBox by holding its Top-Left corner, so this code first gets the distance between Left/Top PictureBox borders and the X/Y coordinates where the mouse moves (before dragging start), so having this offsets, when dragging starts by holding left mouse button down we can substract them from Left and Top to be able to drag the control by taking it from the real spot where the user clicked inside the PictureBox. Static variables are perfect for doing this since they always retain the value they had the last time the Sub/Function executed, keeping this value even when the Sub/Function where they are declared lose scope. Using modular declared variables for doing this would be exactly the same thing.
EDIT: I see you'll also need transparency, then a PictureBox may not be enough for that, you could use other sort of control like the controls Lavolpe's submitted to the CodeBank.
Thanks for adding that, but this has nothing to do with the mouse as i told jmsrickland. Don't need transparency
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 11th, 2012, 02:57 AM
#11
Re: best way to float and move randomly a picture on top of a vb6 form
What is the movement you need the PBox to perform? like a ball bouncing inside the Form's borders or what?
-
Aug 11th, 2012, 03:07 AM
#12
Thread Starter
PowerPoster
Re: best way to float and move randomly a picture on top of a vb6 form
 Originally Posted by jcis
What is the movement you need the PBox to perform? like a ball bouncing inside the Form's borders or what?
was thinking kind of like as screen saver where the pic just floats around without disappearing past the form.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 11th, 2012, 02:57 PM
#13
Re: best way to float and move randomly a picture on top of a vb6 form
See this example, add a Timer and a PictureBox (Timer1 and Picture1)
Code:
Private Const mSpeed As Single = 5
Private Sub Form_Load()
With Picture1
.AutoSize = True
.BorderStyle = 0
.BackColor = vbYellow
.Picture = Me.Icon
End With
Timer1.Interval = 1
Timer1.Enabled = True
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
End Sub
Private Sub Timer1_Timer()
Static GoingLeft As Boolean, GoingUp As Boolean
Dim NewX As Single, NewY As Single
With Picture1
If GoingLeft Then
If .Left - mSpeed <= 0 Then
NewX = .Left
GoingLeft = False
Else
NewX = .Left - mSpeed
End If
Else
If .Left + .ScaleWidth + mSpeed >= Me.ScaleWidth Then
NewX = Me.ScaleWidth - .ScaleWidth
GoingLeft = True
Else
NewX = .Left + mSpeed
End If
End If
If GoingUp Then
If .Top - mSpeed < 0 Then
NewY = .Top
GoingUp = False
Else
NewY = .Top - mSpeed
End If
Else
If .Top + .ScaleHeight + mSpeed > Me.ScaleHeight Then
NewY = Me.ScaleHeight - .ScaleHeight
GoingUp = True
Else
NewY = .Top + mSpeed
End If
End If
.Move NewX, NewY
End With
End Sub
You can resize your Form even at runtime to test that the PictureBox is confined inside the Form. You can also change speed by using different values for constant mSpeed.
Last edited by jcis; Aug 11th, 2012 at 03:03 PM.
-
Aug 11th, 2012, 03:31 PM
#14
Re: best way to float and move randomly a picture on top of a vb6 form
Hi jcis,
That's pretty cool app. I did one like that in Java using many balls balls bouncing off the walls of the Form and if any two collided they blew up. I'm wondering, however, if this will resolve the OP's request as I was under the impression that he wanted a random like movement without any reason to direction of the object instead of straight-line. I guess he will say so.Anyway, like I said, it is a really cool app.
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.
-
Aug 11th, 2012, 03:31 PM
#15
Re: best way to float and move randomly a picture on top of a vb6 form
Hi jcis,
That's pretty cool app. I did one like that in Java using many balls balls bouncing off the walls of the Form and if any two collided they blew up. I'm wondering, however, if this will resolve the OP's request as I was under the impression that he wanted a random like movement without any rhyme or reason to direction of the object, kind of like an aquarium of fish freely swimming around in all directions, instead of straight-line. I guess he will say so. Anyway, like I said, it is a really cool app.
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.
-
Aug 11th, 2012, 03:47 PM
#16
Re: best way to float and move randomly a picture on top of a vb6 form
Well, this is how Windows screensavers do it, the image bouncing on the screen borders in 90 degree angles. The movement will look less repetitive If the Form is not a perfect square. Anyway many other effects can be made, for example, by suddenly using different speeds for x and y or making not linear movement, curves, spiral, whatever..
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
|