VB中怎么限制Text1中只能输入文字,比如汉字,不能输入数字

2024-12-26 18:06:29
推荐回答(1个)
回答1:

Private Sub Text1_KeyPress(KeyAscii As Integer) '只能输入汉字
If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer) '只能输入数字0~9
If KeyAscii >= 48 And KeyAscii <= 57 Then
Else
KeyAscii = 0
End If
End Sub