Last active
January 26, 2016 15:03
-
-
Save Laicure/5a48599987054f129b62 to your computer and use it in GitHub Desktop.
[vb] Form Drag Snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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