Click here to Skip to main content
13,054,615 members (59,811 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.


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))

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
        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 22:01pm
Updated 28-Aug-14 21:46pm
Sergey Alexandrovich Kryukov 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?

1 solution

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

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 29 Aug 2014
Copyright © CodeProject, 1999-2017
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