1,105,391 Community Members

Mouse.Click and Mouse.MouseDown

Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
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

Member Avatar
Oxiegen
Master Poster
765 posts since Jun 2006
Reputation Points: 88 [?]
Q&As Helped to Solve: 149 [?]
Skill Endorsements: 7 [?]
Featured
 
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?

Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

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

Member Avatar
Oxiegen
Master Poster
765 posts since Jun 2006
Reputation Points: 88 [?]
Q&As Helped to Solve: 149 [?]
Skill Endorsements: 7 [?]
Featured
 
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
Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
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
Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
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
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: