Skip to content

Instantly share code, notes, and snippets.

@Laicure
Last active January 26, 2016 15:03
Show Gist options
  • Save Laicure/5a48599987054f129b62 to your computer and use it in GitHub Desktop.
Save Laicure/5a48599987054f129b62 to your computer and use it in GitHub Desktop.
[vb] Form Drag Snippet
Module FormDrag
'********** Form Set Variables
Private dragging As Boolean
Private mXx As Integer
Private mYy As Integer
'Form Drag
''MouseDown
Friend Sub FormDragDown()
dragging = True
mXx = Windows.Forms.Cursor.Position.X - Form.ActiveForm.Left
mYy = Windows.Forms.Cursor.Position.Y - Form.ActiveForm.Top
End Sub
''MouseMove
Friend Sub FormDragMove()
If dragging = True Then
Try
Form.ActiveForm.Top = Windows.Forms.Cursor.Position.Y - mYy
Form.ActiveForm.Left = Windows.Forms.Cursor.Position.X - mXx
If Form.ActiveForm.Top >= (Screen.PrimaryScreen.Bounds.Height - 50) Then
Form.ActiveForm.Top = Screen.PrimaryScreen.Bounds.Height - 50
End If
If Form.ActiveForm.Top <= 0 Then
Form.ActiveForm.Top = 0
End If
Catch ex As Exception
dragging = False
End Try
End If
End Sub
''MouseUp
Friend Sub FormDragUp()
dragging = False
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment