Ive seen this topic quite a bit in the VB.NET Forums; people wanting to move Borderless Forms and such. So here's a tutorial to simply show you how easy it is.
First, we need to declare our variables:
CODE
Dim drag As Boolean
Dim mousex As Integer
Dim mousey As Integer
Next we need to tell the application its time to drag by setting drag to true and then letting the form know which way or location to head by getting the position of our Cursor:
CODE
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
drag = True
mousex = Windows.Forms.Cursor.Position.X - Me.Left
mousey = Windows.Forms.Cursor.Position.Y - Me.Top
End Sub
The code below actually does the moving of the Form for us. Since we clicked on the Form, drag was set to true so now as we move our mouse the Form will follow:
CODE
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If drag Then
Me.Top = Windows.Forms.Cursor.Position.Y - mousey
Me.Left = Windows.Forms.Cursor.Position.X - mousex
End If
End Sub
Finally, its time to stop dragging the form so as we release our mouse from the Form, drag needs to be set to false so it wont move anywhere until its clicked again:
CODE
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
drag = False
End Sub
Pretty simple, no?