VB.Net block of code to create a borderless dragable window/form for VB.net application.
Code:
'make sure you write this entire block of code outside all methods inside your class
Private IsFormBeingDragged As Boolean = False
Private MouseDownX As Integer
Private MouseDownY As Integer
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = True
MouseDownX = e.X
MouseDownY = e.Y
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Left Then
IsFormBeingDragged = False
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove
If IsFormBeingDragged Then
Dim temp As Point = New Point()
temp.X = Me.Location.X + (e.X - MouseDownX)
temp.Y = Me.Location.Y + (e.Y - MouseDownY)
Me.Location = temp
temp = Nothing
End If
End Sub
I hope my article helped you and If you want to see live testing of how this works for a better explanation watch my Youtube Video. Still, if you have got any difficulties or doubts/queries then feel free to leave a comment below or mail us. You can also inbox us at our official Facebook page.
If you liked our article then please do subscribe to our page for more articles like this and do leave a comment below.
Also, follow us on all our social media handles from the follow us tab from the top right sidebar.

Comments
Post a Comment