Advertisement
CorrM

MovableGridView

Aug 1st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.19 KB | None | 0 0
  1. '''
  2. ''' How To Use
  3. '''
  4. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  5.     Dim CorrM As MovableGridView = New MovableGridView(DataGridView1)
  6. End Sub
  7.  
  8. '''
  9. ''' Coded By CorrM 8/2/2017
  10. '''
  11.  
  12. Public Class MovableGridView
  13.     Private WithEvents _Gridv As DataGridView
  14.     Private CanMove As Boolean = False
  15.     Private MouseLoc As Point
  16.  
  17.     Sub New(ByRef Gridv As DataGridView)
  18.         _Gridv = Gridv
  19.     End Sub
  20.  
  21.     Private Sub Gridv_MouseDown(sender As Object, e As MouseEventArgs) Handles _Gridv.MouseDown
  22.         If e.Button = MouseButtons.Left Then
  23.             CanMove = True
  24.             MouseLoc.X = e.X
  25.             MouseLoc.Y = e.Y
  26.         End If
  27.     End Sub
  28.  
  29.     Private Sub Gridv_MouseUP(sender As Object, e As MouseEventArgs) Handles _Gridv.MouseUp
  30.         CanMove = False
  31.     End Sub
  32.  
  33.     Private Sub _Gridv_MouseMove(sender As Object, e As MouseEventArgs) Handles _Gridv.MouseMove
  34.         If CanMove Then
  35.             Dim MoveX As Integer = e.X - MouseLoc.X
  36.             Dim MoveY As Integer = e.Y - MouseLoc.Y
  37.             _Gridv.Location = New Point(_Gridv.Location.X + MoveX, _Gridv.Location.Y + MoveY)
  38.         End If
  39.     End Sub
  40.  
  41. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement