Hello my fellow Danniwebbers, I have yet another question for you to ponder.

I have two custom action listers. One that handles Mouse.Click and one that handles Mouse.MouseDown.

My question to you is, can I delay the mouse down event so that it does not intefere with the code of the Mouse.Click event?

I have tried adding a timer and waiting x amount then setting a bool value to true, but the code executes to fast and it skips the other code.

Any tips?

Thanks,
Begginnerdev

Why not skip the MouseDown event all together and move that code into a method that you call at the end of execution in the MouseClick event?

It is basicly control relocation code. User clicks/holds left mouse > drag > release.

Alright.
Then you can probably add a boolean variable that checks wether or not the mousebutton has been released.
And if so, exit from the MouseDown event.
I don't know if this is going to work. I've never tried it myself, but it should give you some ideas.

Private Sub control_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles control.MouseDown
    If bMouseClicked = True Then Return

    'The original MouseDown code
End Sub

Private Sub control.MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles control.MouseClick
    bMouseClicked = e.Clicks > 0
End Sub

I have tried, but the interpreter skips the code. :(
I have found an article that said the .NET events are supposedly fired in the following order

MouseDown
Click
MouseUp

Which completely destroys my code setup. I need to be able to click to referece the control, and mousedown/up to drag the control to where I need it to be.

Member Avatar for Unhnd_Exception

This will do a "click" and a "mouse drag". I think thats what your looking for.

This doesn't use the mouseclick event but simulates a mouseclick in the mouse up. You would need to put your mouseclick code in the mouseup shown below.

 Private MouseMoved As Boolean
 Private MoveOffset As Point

 Private Sub Button2_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown

    If e.Button = Windows.Forms.MouseButtons.Left Then
        MouseMoved = False
        MoveOffset = New Size(e.Location.X, e.Location.Y)
    End If

 End Sub

 Private Sub Button2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseMove
    'move the button if the left mouse button is held'
    If e.Button = Windows.Forms.MouseButtons.Left Then
        MouseMoved = True
        Button2.Location += New Size(e.Location.X - MoveOffset.X, e.Location.Y - MoveOffset.Y)
    End If
 End Sub

 Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp
    'simulate a mouse click.'
    'if the mouse did not move and the cursor'
    'is inside the button when released then'
    'its a click.'
    If Not MouseMoved AndAlso Button2.ClientRectangle.Contains(e.Location) Then
        'mouse click code'
        MsgBox("Clicked")
    End If
 End Sub

I have found a solution.
I placed the code into a timer, and then placed an IF statement saying

If valueOfTimer > 15 Then
'code'
End IF
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.