DIM MousePos2 As Point 'Defines Mouse Position Variables
DIM DRAGING As Boolean = FALSE
DIM DRAGRECT AS Rectangle
PRIVATE SUB button2_mousedown (Byval e as system.windows.forms.mouseeventargs) Handles Button2.MouseDown
IF Draging = false
Dragging = TRUE
MousePos2 = New Point (MousePosition.x - Left - Button2.Left, MousePosition.y - Top - Button2.top) 'Mouse points on the button on the button on the button
Makerect ()
END IF
End Sub
Private sub makeect ()
The parameter of the 'NEW method represents the left upper corner position and size (wide and high) of the rectangular area (wide and high)
'ClientSize is the size of the work area ()
DragRect = New Rectangle (Left Mousepos2.x, Top Mousepos2.y, ClientSize.width - Button2.Width, Clientsize.Height - Button2.Height "This area is the maximum area that the button can active.
End Sub
Private sub button2_mousemove (Byval e as system.windows.forms.mouseeventargs) Handles Button2.Mousemove
IF Draging Then
If Me.MousePosition.x Button2.left = 0 'If you want to move it to the left, move to the left edge Elseif MousePosition.x> DRAGRECT.Right THEN Button2.Left = clientsize.width - button2.width 'wants to move out to the right, then move to the right edge Else Button2.x - left - mousepos2.x END IF If MousePosition.y Button2.top = 0 'Similarly, moving uploads are not allowed to exceed the upper boundary Elseif MousePosition.y> DragRect.Bottom Then Button2.top = clientsize.height - button2.height 'moves down without going out Else Button2.top = mouseposition.y - top - mousepos2.y END IF END IF End Sub Private sub button2_mouseup (Byval e as system.windows.forms.mouseeventargs) Handles Button2.Mouseup Dragging = false End