VB Tutorial
Tools
Free Downloads
Free Link Directory

Basics
Data Types
Windows Forms
Buttons
Check Box
Text Box
Combo Box
Radio Buttons
Progress Bar
Color & Font Dialogs
Open & Save Dialogs
Process Control

More Complex Examples
Audio Player
Rotating Rectangle

Vb.Net How to drag a form on Mouse Down

See the code use in an example- Borderless Form in Visual Basic

I find the code beneath to be the very simplest and effective way to move a windows form with no border across the desktop in Visual Basic and Vb.Net

Public Class Form1

Dim isMouseDown As Integer ''' To check if mouse is down
Dim MyX, MyY As Integer ''' To calculate in which direction form should move

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
isMouseDown = 1 '''to check if mouse is down
MyX = e.X : MyY = e.Y ''' to calculate form/mouse position increase or decrease
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
'''Code to move the form when the mouse is down
If isMouseDown = 1 Then ''' Move form only when mouse button is pressed down on form
If e.X > MyX Then Me.Left = Me.Left + 1
If e.X < MyX Then Me.Left = Me.Left - 1
If e.Y > MyY Then Me.Top = Me.Top + 1
If e.Y < MyY Then Me.Top = Me.Top - 1
End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
isMouseDown = 0 ''' to check if mouse is down
Me.Cursor = Cursors.Default
End Sub

End Class

Download Project File

If you liked this article then Please Thumb This Up with a short review - Stumble It!

 

 

 

 

 

 

 

 

 


Email us at: info@pro2visual.com

Get your Website Listed on our Free Link Banner Directory
Advertise your site with your own unique link banner we will also provide text links to your site.

 

Popular Articles

Moving a borderless form in vb.net

ComboBox1.Items.Add

Link Progress Bar with Timer in vb.net

How to open a folder using the process control

Start Vb.net programming. No get rich quick scam

How to Convert the Date Format

Click here for Industry Leading Development Softwa