我想请问VB中,双击鼠标事件必定会导致单击事件,那么怎么解决这个问题呢?
3个回答
展开全部
你那个恐怕不好实现、
但是我想也没有什么程序一定需要设定单击和双击的不同动作吧?
比如windows中,单击文件是选中,双击是打开。但是双击的时候其实也是先选中了。
所以你的程序中最好两个事件的代码不是互相排斥的。
另外下面的代码可以供你参考
'本代码演示如何获取鼠标按下和放开的间隔时间
Private Declare Function GetDoubleClickTime Lib "user32" () As Long
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Dim T1 As SYSTEMTIME
Dim T2 As SYSTEMTIME
Private Sub Form_Load()
'显示系统中设定的判定双击的时间间隔
MsgBox ("判定双击的时间间隔=" & GetDoubleClickTime)
End Sub
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetLocalTime T1
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetLocalTime T2
MsgBox ("你按下和放开鼠标的时间间隔为" & CalcSJC)
End Sub
Private Function CalcSJC() As Integer
Dim a As Double
b = Val(T1.wSecond)
a = Val(T1.wSecond) * 1000 + Val(T1.wMilliseconds)
If Val(T2.wSecond) < b Then
c = (Val(T2.wSecond) + 60) * 1000 + Val(T2.wMilliseconds)
Else
c = Val(T2.wSecond) * 1000 + Val(T2.wMilliseconds)
End If
shijiancha = c - a
CalcSJC = shijiancha
End Function
但是我想也没有什么程序一定需要设定单击和双击的不同动作吧?
比如windows中,单击文件是选中,双击是打开。但是双击的时候其实也是先选中了。
所以你的程序中最好两个事件的代码不是互相排斥的。
另外下面的代码可以供你参考
'本代码演示如何获取鼠标按下和放开的间隔时间
Private Declare Function GetDoubleClickTime Lib "user32" () As Long
Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Dim T1 As SYSTEMTIME
Dim T2 As SYSTEMTIME
Private Sub Form_Load()
'显示系统中设定的判定双击的时间间隔
MsgBox ("判定双击的时间间隔=" & GetDoubleClickTime)
End Sub
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetLocalTime T1
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
GetLocalTime T2
MsgBox ("你按下和放开鼠标的时间间隔为" & CalcSJC)
End Sub
Private Function CalcSJC() As Integer
Dim a As Double
b = Val(T1.wSecond)
a = Val(T1.wSecond) * 1000 + Val(T1.wMilliseconds)
If Val(T2.wSecond) < b Then
c = (Val(T2.wSecond) + 60) * 1000 + Val(T2.wMilliseconds)
Else
c = Val(T2.wSecond) * 1000 + Val(T2.wMilliseconds)
End If
shijiancha = c - a
CalcSJC = shijiancha
End Function
展开全部
你的动作是单击还是双击是系统定义的,去控制面板看一下,鼠标有一项设置叫双击时间间隔,他决定了你两次单击是不是双击。
从编程的角度,你编写的程序的窗口收到的双击的消息是来自系统的,在用户两次单击时,如果系统检测到两次的时间间隔小于上面设定的那个值,就当成是双击,如果不是的话,就是两次单击。
从编程的角度,你编写的程序的窗口收到的双击的消息是来自系统的,在用户两次单击时,如果系统检测到两次的时间间隔小于上面设定的那个值,就当成是双击,如果不是的话,就是两次单击。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不会的吧?是不是你双击间隔太长了?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询