Very simple way to move a form holding down mouse button





5.00/5 (3 votes)
Charles henington, you can consider this as VB.NET.F5 is nothing but start debugging. You got my 5.Public Class Form1 Dim pastx, pasty, presentx, presenty, bt As Integer Sub moving() Dim xx, yy As Integer xx = presentx - pastx yy = presenty - pasty ...
Charles henington, you can consider this as VB.NET.
F5 is nothing but start debugging. You got my 5.
Public Class Form1
Dim pastx, pasty, presentx, presenty, bt As Integer
Sub moving()
Dim xx, yy As Integer
xx = presentx - pastx
yy = presenty - pasty
If bt Then 'set your condition: left btn or right btn or mid btn
Me.Left = Me.Left + xx
Me.Top = Me.Top + yy
End If
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
pastx = e.X
pasty = e.Y
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
presentx = e.X
presenty = e.Y
bt = e.Button
moving()
End Sub
End Class