我想在输入框中显示一个字符:长按一下点击并点击.
点-
。例如,按住左键2秒将显示破折号而不是点。
我已经尝试过双击,这是我的代码:
Private Sub input_Click()
Me.input.Value = "." + Me.input.Value
End Sub
Private Sub input_DblClick(Cancel As Integer)
Me.input.Value = "-" + Me.input.Value
End Sub
这里的问题是,当我双击时,它会通过点击并显示点和短划线,当它只是显示短划线时。
我想补充一点,我只需要点击左键即可。没有键盘,没有右键单击。
这就是为什么我的想法是使用点击点击并双击短划线,或点击并长按。
我知道如果在VBA上使用if语句并在不使用双击事件的情况下检查它是单击还是双击。
答案 0 :(得分:3)
在表单模块的标题中定义以下变量:
Private isMouseKeyPreessed As Boolean
Private timeMouseKeyPreessed As Date
然后为名为MouseUp
的文本框定义MouseDown
和input
个事件(顺便说一下,它是错误的名称,因为input
是保留字):
Private Sub input_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = acLeftButton Then
isMouseKeyPreessed = True
timeMouseKeyPreessed = Now
End If
End Sub
Private Sub input_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Delta As Double
Dim symbol As String
If Button = acLeftButton Then
isMouseKeyPreessed = False
Delta = Now - timeMouseKeyPreessed
If Delta > 0.00002 Then
' 0.00002 - is a value to tune up to get exactly 2 seconds
' it should be about
' cdbl(timeserial(0,0,2)-timeserial(0,0,0))
symbol = "-"
Else
symbol = "."
End If
Me.input.Value = symbol & Me.input.Value
End If
End Sub