Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF VB.NET
Hi all,
 
How to know if the mouse action is still on click?
I'm about to do a click and hold function. A timer will start when mouse is click on certain position. And when the timer is tick, I want to detect is the mouse is still click then I do run my other code.
 

EDITED:
 
This is how I made the code just like your tap + hold on smartphone.
 
Dim point1, point2 As Point
Dim WithEvents tmrhold As New DispatcherTimer
When button.Click or rectangle.MouseDown, I start the timer and locate the first mouse position.
tmrhold.Interval = TimeSpan.FromMilliseconds(1000)
point1 = Me.PointToScreen(Mouse.GetPosition(Me))
tmrhold.Start()
When timer tick, I check again the current position and compare it with first position. And I make sure the mouse is on click. If I don't do that, when I click and leave the mouse on the same position, it has the same position but not as same action (user still on click). So check if user still on click and position is same.
Private Sub tmrhold_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrhold.Tick
        tmrhold.Stop()
        If Mouse.LeftButton = MouseAction.LeftClick Then
            point2 = Me.PointToScreen(Mouse.GetPosition(Me))
            If point2 = point1 Then
                'Handle code
            End If
        End If
End Sub
Posted 26-Aug-14 23:01pm
Edited 28-Aug-14 22:46pm
v2
Comments
Sergey Alexandrovich Kryukov at 27-Aug-14 11:17am
   
I answered the question by commenting on the Solution 1. Is it clear how can you achieve the functionality you need, with a timer?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should he able to use the mousedown event[^].
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 27-Aug-14 11:16am
   
It actually requires to handle MouseUp as well :-)
Please read the question.
—SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 535
1 Kornfeld Eliyahu Peter 407
2 Maciej Los 369
3 DamithSL 221
4 OriginalGriff 218
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 29 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100