Click here to Skip to main content
15,889,527 members
Articles / Programming Languages / Visual Basic 6
Alternative
Tip/Trick

Very simple way to move a form holding down mouse button

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
16 Mar 2011CPOL 5.5K   1  
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.

VB
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Arisaf Tech
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --