Mouse Event Problems

mpappert

Regular
Joined
Oct 5, 2002
Messages
58
Location
Ottawa, ON, Canada
Hey Everyone,

I'm working on creating a custom form layout (basically replace the default TitleBar with one of my own creations) .. I'm having problems with tracking mouse events ... It moves but the form moves 'jittery' and when you do a small movement and stop (not releasing the mouse button) the form still jitters until you let go of the mouse. It's also very slow ... here is my code, am I missing something?

TIA!
M.



Code:
    Private blnMouseDown As Boolean
    Private MouseLocXonClick As Integer
    Private MouseLocYonClick As Integer

    Private Sub lblTitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseDown

        blnMouseDown = True
        MouseLocXonClick = e.X
        MouseLocYonClick = e.Y

    End Sub


    Private Sub lblTitleBar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseMove

        If blnMouseDown Then

            Me.Left = e.X - MouseLocXonClick
            Me.Top = e.Y - MouseLocYonClick

        End If

    End Sub


    Private Sub lblTitleBar_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseUp

        blnMouseDown = False

    End Sub
 
Man, just as I post I figured it out! LOL .. Anyways, for anyone else wanting to do this .. here is the code that works .. :)

M.



Code:
    Private blnMouseDown As Boolean
    Private MouseLocXonClick As Integer
    Private MouseLocYonClick As Integer

    Private Sub lblTitleBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseDown

        blnMouseDown = True
        MouseLocXonClick = e.X
        MouseLocYonClick = e.Y

    End Sub


    Private Sub lblTitleBar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseMove

        If blnMouseDown Then

            Me.Left = Me.Left + (e.X - MouseLocXonClick)
            Me.Top = Me.Top + (e.Y - MouseLocYonClick)

        End If

    End Sub


    Private Sub lblTitleBar_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseUp

        blnMouseDown = False

    End Sub
 
Try replacing the MouseMove code with this:
Code:
    Private Sub lblTitleBar_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
     Handles lblTitleBar.MouseMove

        If blnMouseDown Then

            Me.Location = New Drawing.Point(Me.Location.X + (e.X - MouseLocXonClick), _
                                            Me.Location.Y + (e.Y - MouseLocYonClick))
        End If

    End Sub

edit: well, I guess you figured it out on your own.
 
Back
Top