Here's an example that makes the form follow the cursor when the left mousebutton is clicked:
Private mouse_offset As Point
Private Sub my_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseDown
mouse_offset = New Point(-e.X, -e.Y)
End Sub
Private Sub my_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Dim mousePos As Point = Me.MousePosition
mousePos.Offset(mouse_offset.X, mouse_offset.Y)
Me.Location = mousePos
End If
End Sub
You can also do that by overRiding WndProc, but I can't seem to find the code right now.
By the way, here's a description of the SetCapture function in the user32.dll library:
SetCapture captures the mouse for the specified window. When a window captures the mouse, it receives all mouse input messages, including those which would otherwise be sent to other windows. Capturing the mouse input allows a window to keep track of all mouse actions via mouse messages, but no other windows will receive the mouse input. When the capture is no longer needed, the mouse capture should be ended by calling ReleaseCapture.