1.11M Members

Mouse.Click and Mouse.MouseDown

 
0
 

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

 
0
 

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?

 
0
 

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

 
0
 

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
 
0
 

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.

Unhnd_Exception
Deleted Member
 
0
 

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
 
0
 

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
Question Answered as of 2 Years Ago by Oxiegen and Unhnd_Exception
Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: