H
hooksie2
I want to be able to drag a label (or other suitable control to act
like a box) on a userform at runtime.
I have written the following to do this but have these problems:
1) the movement is quite jerky - at times the label can even jump
backwards although I am only moving the mouse fowards
2) the mouse gets ahead of the label
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Static sngXOld As Single
Dim sngDelta As Single
If m_blnMouseIsDown Then
sngDelta = (X - sngXOld)
Me.Label1.Left = Me.Label1.Left + sngDelta
Me.Label2.Left = Me.Label2.Left + sngDelta
DoEvents
sngXOld = X
End If
End Sub
I can improve things a little bit by only moving the label once the
mouse is moved a certain minimum distance, ie. If Abs(sngDelta) > 5,
but it's still not perfect and the mouse still gets ahead of the label.
Can anyone suggest an alternative approach - or have I simply
overlooked something here?
Thanks a lot,
Andrew
like a box) on a userform at runtime.
I have written the following to do this but have these problems:
1) the movement is quite jerky - at times the label can even jump
backwards although I am only moving the mouse fowards
2) the mouse gets ahead of the label
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Static sngXOld As Single
Dim sngDelta As Single
If m_blnMouseIsDown Then
sngDelta = (X - sngXOld)
Me.Label1.Left = Me.Label1.Left + sngDelta
Me.Label2.Left = Me.Label2.Left + sngDelta
DoEvents
sngXOld = X
End If
End Sub
I can improve things a little bit by only moving the label once the
mouse is moved a certain minimum distance, ie. If Abs(sngDelta) > 5,
but it's still not perfect and the mouse still gets ahead of the label.
Can anyone suggest an alternative approach - or have I simply
overlooked something here?
Thanks a lot,
Andrew