Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= Asc("a") And KeyAscii <= Asc("z")) Or KeyAscii = vbKeySpace Or KeyAscii < 0 Then
Else
KeyAscii = 0
End If
End Sub
即可!
小写字母和空格都好控制,用textbox_keypress即可控制。下面是一个控制只输入数字和小数点的例子:
Private Sub text_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Or KeyAscii = 46 Or KeyAscii <= 57 And KeyAscii >= 48 then
Exit Sub
Else
KeyAscii = 0
End If
End Sub