我的比你的要方便,可以灵活的限制复杂的内容:
配合MaxLength属性
Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case Chr(KeyAscii)
        Case "0"
        Case "1"
        Case "2"
        Case "3"
        Case "4"
        Case "5"
        Case "6"
        Case "7"
        Case "8"
        Case "9"
        Case "."
        Case Chr(8)
        Case Else
            KeyAscii = 0
    End Select
End Sub

解决方案 »

  1.   

    这个呢?
    Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer  '限制输入
    Dim ValidateList As String
    Dim KeyOut As Integer
    If Editable = True Then
    ValidateList = UCase(ValidateString) & Chr(8)
    Else
    ValidateList = UCase(ValidateString)
    End If
    If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
    KeyOut = KeyIn
    Else
    KeyOut = 0
    Beep
    End If
    ValiText = KeyOut
    End Function调用:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    KeyAscii = ValiText(KeyAscii, "0123456789", True)
    End Sub
      

  2.   

    TO 大菜
    怎么处理中文?
    怎么限制回车光标和其他的?需要同意输入字母呢?
    TO 小半:

    没有我的简洁
      

  3.   

    另一点:如果使用CTR+V粘贴进中文或其他符号又如何?? 未经过KEYPRESS。