|
-
May 27th, 2002, 01:38 PM
#1
Thread Starter
New Member
Moving Pictures
Im working on a Resident-Evilish type game on Visual Basics. Im working on a puzzle right now, and I need some help with a simple thing I cant seem to figure out.
I need to know how to move a picture or Image across the screen by clicking and dragging the mouse.
I dont know if this is possible, but if it is any one can help me out, I thank you greatly!
-
May 27th, 2002, 02:20 PM
#2
Good Ol' Platypus
Sure it is. What you do is on the MouseDown event jot down the X and Y coords. Make a boolean that says dragging (cant be local, must be global) and set it to true. Then, on the MouseOver event, see if dragging is true, and if it is, move the picturebox right NewX - ClickX units, and NewY - ClickY units. On the MouseUp event, set dragging to false.
Unfortunately this has erratic behaviour and doesn't work well. As I recall there is an API version. You may want to look for that.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
May 27th, 2002, 02:41 PM
#3
Thread Starter
New Member
lol thanks for the help but im not so fluent in this "VB talk". Im rather new to this world of coding and I can do the simple's and make something real great, but I dont understand the "talk"
So if its not too much trouble, could anyone Translate what he was saying into english?
-
May 27th, 2002, 04:01 PM
#4
PowerPoster
Well... to drag a picture you need 3 values, the position when you click the picture, the current cursor position when moving it and the picture's position. The cursor position is given to you in the MouseMove event. If the user doesn't hold any button you store the cursor position for later use. When a button is pressed and the cursor moves you get the difference of the current and the last cursor position and add them to the picture box' position.
Sample: Open a new project, add a picture box and insert this code:
VB Code:
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Static means that the variables aren't set
'back to 0 when the function is called again
Static X2 As Long
Static Y2 As Long
If Button = 1 Then
'Holding left button
'Add difference from current to last cursor
'position to the picture box' coordinates
Picture1.Move Picture1.Left - (X2 - X), Picture1.Top - (Y2 - Y)
Else
'Store mouse position if no button pressed
X2 = X
Y2 = Y
End If
End Sub
-
May 27th, 2002, 04:07 PM
#5
Thread Starter
New Member
Thanks alot, you just saved me from hours of suffering.
Everyone I asked didnt know the answer at all, but alas, you did!
Thanks again ^_^
-
May 27th, 2002, 04:14 PM
#6
PowerPoster
I'm quite sure they all know, however
-
May 27th, 2002, 04:36 PM
#7
Good Ol' Platypus
I would've posted code but I'm feeling sick today - sorry
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
May 27th, 2002, 04:58 PM
#8
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
|