如何实现敲两下回车响应一个事件 vb

来源:百度知道 编辑:UC知道 时间:2024/06/05 23:10:15
text1中如何实现敲两下回车响应一个事件

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then

现在只能敲一下,敲两下才响应事件如何改?
看了两位高手的说明,我修改后还是不管用,我把相关代码发来,你们帮忙改改,成了我追加分,谢谢
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 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

★☆答案已按你的要求作了修改,经测试通过。
粘贴代码覆盖你问题里的代码即可。
===================
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

建个过程,或全局变量
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
Pr