G37Sam
Registered User.
- Local time
- Today, 07:41
- Joined
- Apr 23, 2008
- Messages
- 454
Hello All,
I have a form wherein I'd like to drag and drop multiple labels, I was able to do this for one label and figured there must be some sort of technique wherein I wouldn't have to re-write the code for every single label. A little research pointed me towards class modules and I ended up patching together the below code.
Now how do I "attach" the below class module to labels on my form to trigger the below events automatically? Am I making sense?
I have a form wherein I'd like to drag and drop multiple labels, I was able to do this for one label and figured there must be some sort of technique wherein I wouldn't have to re-write the code for every single label. A little research pointed me towards class modules and I ended up patching together the below code.
Now how do I "attach" the below class module to labels on my form to trigger the below events automatically? Am I making sense?
Code:
Option Explicit
Public WithEvents DragLabel As Form.Label
Dim MoveMe As Boolean
Dim InitX As Long
Dim InitY As Long
Dim DragX As Long
Dim DragY As Long
Private Sub DragLabel_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = acLeftButton And Shift = acCtrlMask Then
MoveMe = True
InitX = X
InitY = Y
Else
MoveMe = False
End If
End Sub
Private Sub DragLabel_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If MoveMe = True Then
DragX = X
DragY = Y
End If
End Sub
Private Sub DragLabel_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If MoveMe = True Then
With DragLabel
.Left = .Left + DragX - InitX
.Top = .Top + DragY - InitY
End With
MoveMe = False
End If
End Sub