by Michael Klinteberg (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating:
(3 Votes)

Use this code to drag and drop (almost) any control anywhere on a form.
Assumes
Add some controls and a checkBox Named chkOnOff
API DeclarationsOption Explicit
Private Sub chkOnOff_Click()
On Error Resume Next 'resume next beacuse not all controls support dragmode
Dim ctl As Control
'Turn dragmode on/off
If chkOnOff.Value Then
For Each ctl In Me.Controls
'Debug.Print TypeName(ctl)
ctl.DragMode = vbAutomatic
Next
Else
For Each ctl In Me.Controls
'Debug.Print TypeName(ctl)
ctl.DragMode = vbManual
Next
End If
Me.chkOnOff.DragMode = vbManual
End Sub
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
'Move the control
Source.Top = Y
Source.Left = X
End Sub