JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: Line Control Archived to Disk
The code to move the line is the same as the code to move a control, with the exception that you use the (X,Y) instead of (left,top) and you have to keep track of the line's "width" and "height".
Option Explicit
Private Type tCoords
X As Single
Y As Single
End Type
Private fMoving As Boolean
Private tMoving As tCoords
Private Sub Form_Load()
With tMoving
.X = -1
.Y = -1
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim X2 As Long
Dim Y2 As Long
If Not fMoving And Button = 1 Then
If X >= (Line1.X1) And X <= (Line1.X2) Then
' -20 and +20 just to give more of a "grip"
If Y >= (Line1.Y1) - 20 And Y <= (Line1.Y2) + 20 Then
fMoving = True
End If
End If
ElseIf Button <> 1 Then
fMoving = False
End If
If fMoving Then
' If values = -1 then we haven't stored the starup X,Y
If tMoving.X = -1 And tMoving.Y = -1 Then
tMoving.X = X
tMoving.Y = Y
Else
' Move the shape the current position - the difference of the mouse move
' if last X-current X = positive, then move to left (current left - x)
' if last X-current X = negative, then move to right (current left - -x = left + x)
X2 = Line1.X2 - Line1.X1
Y2 = Line1.Y2 - Line1.Y1
Line1.X1 = Line1.X1 - (tMoving.X - X)
Line1.Y1 = Line1.Y1 - (tMoving.Y - Y)
Line1.X2 = Line1.X1 + X2
Line1.Y2 = Line1.Y1 + Y2
tMoving.X = X
tMoving.Y = Y
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
' We're not moving, reset the variables
fMoving = False
With tMoving
.X = -1
.Y = -1
End With
End Sub
|