|
-
Dec 16th, 2002, 02:02 PM
#1
Thread Starter
Member
Draging an image around
Hey there
I'm looking for code to drag an image around on a form. I tried it with the mousedown event of the image but had no luck with that. It should be like the position-bar of winamp... where i can drag the Position-handler to the desired destination.
Any help would be appreciated very much
-
Dec 16th, 2002, 02:11 PM
#2
Record a X and Y coordinat int the mouse down event...and in the mouse move event update the picturebox left and top property after the diffrence in the X and Y coordinate when you started and what they are now....
-
Dec 16th, 2002, 03:23 PM
#3
Frenzied Member
Yes...Here's an example i made some time ago:
Start a new project and add a CommandButton
the paste this code into the form:
VB Code:
Option Explicit
Dim FirstX As Single
Dim FirstY As Single
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
FirstX = X
FirstY = Y
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
If Command1.Left < 0 Then Command1.Left = 0
If Command1.Left > Me.ScaleWidth - Command1.Width Then Command1.Left = Me.ScaleWidth - Command1.Width
If Command1.Top < 0 Then Command1.Top = 0
If Command1.Top > Me.ScaleHeight - Command1.Height Then Command1.Top = Me.ScaleHeight - Command1.Height
If Command1.Left > 0 And Command1.Left < Me.ScaleWidth - Command1.Width Then Command1.Left = Command1.Left + (X - FirstX)
If Command1.Top > 0 And Command1.Top < Me.ScaleHeight - Command1.Height Then Command1.Top = Command1.Top + (Y - FirstY)
If Command1.Left <= 0 And X - FirstX >= 0 Then Command1.Left = Command1.Left + (X - FirstX)
If Command1.Left = Me.ScaleWidth - Command1.Width And X - FirstX <= 0 Then Command1.Left = Command1.Left + (X - FirstX)
If Command1.Top = 0 And Y - FirstY >= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
If Command1.Top = Me.ScaleHeight - Command1.Height And Y - FirstY <= 0 Then Command1.Top = Command1.Top + (Y - FirstY)
Command1.Caption = "(" & Command1.Left / Screen.TwipsPerPixelX & "," & Command1.Top / Screen.TwipsPerPixelY & ")"
End If
End Sub
-
Dec 16th, 2002, 03:40 PM
#4
Yes..that code should do the trick....
-
Dec 16th, 2002, 06:32 PM
#5
Thread Starter
Member
thx alot for the help figured it out by myself in the meantime...
-
Dec 16th, 2002, 07:55 PM
#6
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
|