Private drag As Control
Private Sub frmDiv_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles Me.KeyDown
If e.Shift = False Then Exit Sub
If drag Is Nothing Then
For Each c As Control In Me.Controls
Dim pt As Point = c.PointToClient(System.Windows.Forms.Cursor.Position)
If c.ClientRectangle.Contains(pt) Then
drag = c
Me.Capture = True
Me.Refresh()
Exit Sub
End If
Next
Else
drag = Nothing
Me.Capture = False
Me.Refresh()
End If
End Sub
Private Sub frmDiv_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseMove
If drag IsNot Nothing Then
drag.Location = e.Location
Me.Refresh()
End If
End Sub
Private Sub frmDiv_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If drag IsNot Nothing Then
Dim rct As Rectangle = drag.Bounds
rct.Inflate(1, 1)
e.Graphics.DrawRectangle(Pens.Red, rct)
End If
End Sub