Public Class Form1
Dim Off As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WireButton(Me)
WireLabels(Me)
End Sub
Private Sub WireLabels(ByVal cont As Control)
For Each ctl As Control In cont.Controls
If TypeOf ctl Is Label Then
AddHandler ctl.MouseDown, AddressOf obj1_MouseDown
AddHandler ctl.MouseMove, AddressOf obj1_MouseMove
ElseIf ctl.HasChildren Then
WireLabels(ctl)
End If
Next
End Sub
Private Sub WireButton(ByVal cont As Control)
For Each ctl As Control In cont.Controls
If TypeOf ctl Is Button Then
AddHandler ctl.MouseDown, AddressOf obj1_MouseDown
AddHandler ctl.MouseMove, AddressOf obj1_MouseMove
ElseIf ctl.HasChildren Then
WireButton(ctl)
End If
Next
End Sub
Private Sub obj1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Off.X = MousePosition.X - sender.Left
Off.Y = MousePosition.Y - sender.Top
End Sub
Private Sub obj1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Left Then
sender.Left = MousePosition.X - Off.X
sender.Top = MousePosition.Y - Off.Y
End If
End Sub
End Class