Private DateTime _dt = DateTime.Now;
//定义一个成员函数用于
保存每次的时间点
private void textBox1_KeyPress(object sender, KeyPressEventArgs
e)
{
DateTime.Now;
点
获取时间间隔
DateTime tempDt
=
//保存按键按下时刻的时间
TimeSpan ts = tempDt
.Subtract(_dt);
//
if (ts.Milliseconds >
50)
隔,如果时间间隔大于 50 毫秒,则将 TextBox 清
空
textBox1.Text = "";
dt = tempDt
;
//判断时间间
}
vb:
Private _dt As DateTime = DateTime.Now
'定义一个成员函数用于保
存每次的时间点
Private Sub textBox1_KeyPress(sender As Object, e As
KeyPressEventArgs) Handles replaceppidnew.KeyPress
If e.KeyChar <> Chr(13) Then
下时刻的时间点
间间隔
''禁止用键盘手动输入
Dim tempDt As DateTime = DateTime.Now
'保存按键按
Dim ts As TimeSpan = tempDt.Subtract(_dt)
'获取时
If (ts.Milliseconds > 50) Then
textBox1.Text = ""
'判断时间间隔,如果时间
间隔大于 50 毫秒,则将 TextBox 清空
End If
_dt = tempDt
Else
Me.ActiveControl = textBox1
Me.textBox1.Focus()
End If
End Sub