如何实现敲两下回车响应一个事件 vb
发布网友
发布时间:2024-10-24 02:34
我来回答
共2个回答
热心网友
时间:2024-10-31 08:20
★☆答案已按你的要求作了修改,经测试通过。
粘贴代码覆盖你问题里的代码即可。
===================
Dim i As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
i = i + 1
Else
i = 0
End If
If i = 2 Then
If UCase(RTrim(Text1.Text)) = UCase(Label1.Caption) Then
Text1.Text = ""
Text1.SetFocus
Label2.Caption = "正确"
Else
Text1.Text = ""
Text1.SetFocus
Label2.Caption = "错误"
End If
End If
If KeyAscii = 27 Then
Text1.Text = ""
End If
End Sub
热心网友
时间:2024-10-31 08:24
建个过程,或全局变量
public i
i=0
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
i=i+1
else
i=0 '如果按了其它键就清除第一个加回车记录
exit sub
end if
if i=2 then
'两次回车事件代码
end if
********************************
Public i As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then '先处理其它键
Text1.Text = ""
End If
If KeyAscii = 13 Then
i = i + 1
Else
i = 0 '如果按了其它键就清除第一个加回车记录
Exit Sub
End If
If i = 2 Then
If UCase(RTrim(Text1.Text)) = UCase(Label1.Caption) Then
Text1.Text = ""
Text1.SetFocus
Label2.Caption = "正确"
Else
Text1.Text = ""
Text1.SetFocus
Label2.Caption = "错误"
End If
End If
End Sub
好了,我试过了,复过去就可以用了