Black_Eagle96

Movable Borderless Form

Apr 20th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.08 KB | None | 0 0
  1. Public Class Form1
  2.     'Declare the variables
  3.     Dim drag As Boolean
  4.     Dim mousex As Integer
  5.     Dim mousey As Integer
  6.  
  7.     Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
  8.         drag = True 'Sets the variable drag to true.
  9.         mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
  10.         mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable mousey
  11.     End Sub
  12.  
  13.     Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
  14.         'If drag is set to true then move the form accordingly.
  15.         If drag Then
  16.             Me.Top = Windows.Forms.Cursor.Position.Y - mousey
  17.             Me.Left = Windows.Forms.Cursor.Position.X - mousex
  18.         End If
  19.     End Sub
  20.  
  21.     Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
  22.         drag = False 'Sets drag to false, so the form does not move according to the code in MouseMove
  23.     End Sub
  24. End Class
Advertisement
Add Comment
Please, Sign In to add comment