获取当前的鼠标操作 [英] Get current mouse action

查看:83
本文介绍了获取当前的鼠标操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何知道鼠标操作是否仍在点击?

我即将点击并保持功能。当鼠标点击某个位置时,计时器将启动。当计时器打勾时,我想检测鼠标是否仍然点击然后我运行我的其他代码。





EDITED :



这就是我制作代码的方式就像你在智能手机上点按+保持一样。



< pre lang =vb> Dim point1,point2 As Point
Dim WithEvents tmrhold As DispatcherTimer



当button.Click或rectangle.MouseDown时,我启动计时器并找到第一个鼠标位置。

 tmrhold.Interval = TimeSpan.FromMilliseconds( 1000 
point1 = Me .PointToScreen(Mouse.GetPosition( Me ))
tmrhold.Start()



当计时器打勾时,我再次检查当前位置和c用第一个位置进行操作。我确保点击鼠标。如果我不这样做,当我单击并将鼠标放在相同位置时,它具有相同的位置但不是相同的动作(用户仍然点击)。因此,请检查用户是否仍在点击和位置相同。

 私人  Sub  tmrhold_Tick( ByVal  sender  As  对象 ByVal  e  As  System.EventArgs)句柄 tmrhold.Tick 
tmrhold。停止()
如果 Mouse.LeftButton = MouseAction.LeftClick 然后
point2 = .PointToScreen(鼠标。 GetPosition( Me ))
如果 point2 = point1 然后
' 句柄代码
结束 如果
结束 < span class =code-keyword>如果
结束 Sub

解决方案

你应该能够使用 mousedown 活动 [ ^ ]。


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

解决方案

You should he able to use the mousedown event[^].


这篇关于获取当前的鼠标操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆