Muove dinamicamente controlli




Option Explicit
Dim X1, Y1

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 - Y1
Source.Left = X - X1
End Sub
Name: Move controls in a form
Description:
Use this code to drag and drop (almost) any control
anywhere on a form.

Assumes:
Add some controls and a checkBox Named chkOnOff










( muovedinamicamentecontrolli.html )- by Paolo Puglisi - Modifica del 17/12/2023