这种问题不需要高手进来的!
可控制的有:KeyAscii 、KeyCode

解决方案 »

  1.   

    你需要判断的内容有0~9,最多只能有一个小数点,只能在数字最前有负号,对退格、删除、ESC不能屏蔽,差不多了。限制输入位数可用MaxLength属性。
      

  2.   

    在text的Keypress事件中判断Keyascii来控制只能输出数字或字母或中文等
      

  3.   

    在text的Keypress事件中判断所输入字符的ascii码是否在控制的范围内。这要求你还要熟悉一些字符的ascii码,不过没关系,vb中有一个函数可以得到字符的ascii码。位数用maxlength来限制。
      

  4.   

    给你一个函数:
    '过滤输入为数值
    '参数keyin为输入值,txt为检查数值字符串,editable为是否backspace是否可用,xsw 为小数的位数,position 光标位置
    '调用举例
    'Private Sub Text1_KeyPress(KeyAscii As Integer)
    '    KeyAscii = FilterNum(KeyAscii, Text1.Text, True,Text1.tag,Text1.selstart)
    'End Sub
    Public Function FilterNum(ByVal KeyIn As Integer, ByVal Txt As String, ByVal EditAble As Boolean, ByVal XSW As Integer, ByVal Position As Integer) As Integer
        Dim ValidateList As String
        Dim ValidateString As String
     
        Dim KeyOut As Integer
        Dim i As Integer
        
        ValidateString = "-0123456789."
     
        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
            FilterNum = 0
            Exit Function
        End If
        
        If KeyOut = 8 Then
            FilterNum = 8
            Exit Function
        End If
        
        If (KeyOut = Asc("-")) And Not (Position = 0 And Left(Txt, 1) <> "-") Then
            FilterNum = 0
            Exit Function
        End If
        
        If XSW > 0 Then
            i = InStr(1, Txt, ".", vbTextCompare)
            If i > 0 And KeyOut = Asc(".") Then
                FilterNum = 0
                Exit Function
            End If
            
            If i > 0 And i + XSW = Len(Txt) Then
                If KeyOut <> Asc("-") Then
                    FilterNum = 0
                End If
            End If
            
            If i <= 0 Then
                If Left(Txt, 1) = "-" And KeyOut = Asc(".") And Position = 1 Then
                    FilterNum = 0
                    Exit Function
                End If
            End If
                
        Else
            If KeyOut = Asc(".") Then
                FilterNum = 0
                Exit Function
            End If
        End If
        
        FilterNum = KeyOut
        
    End Function
    '过滤输入文本
    '参数keyin为输入值,validatestring为过滤字符串,editable为是否backspace是否可用。
    '调用举例
    'Private Sub Text1_KeyPress(KeyAscii As In teger)
    '    KeyAscii = FilterNum(KeyAscii, "abc", True)'只可以输入abc
    'End Sub
    Public Function Filtertext(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
        End If
        Filtertext = KeyOut
    End Function
      

  5.   

    看样子你是个新手。上面的写的很清楚了。只是我想说一点就是你可以用KeyAscii 、KeyCode 来做就可以。
      

  6.   

    还有如何限制可输入的位数?text1.MaxLength = 位数(int)
      

  7.   


    ◆第一步:创建窗体Form1
    添加控件:一个TextBox控件,命名为txtTest;一个Frame控件,命名为frameStyles;在其上分别添加三个OptionoptButton控件,命名为optStyle,索引分别为0、1与2。
    ◆第二步:添加代码‘主程序:
    Option Explicit
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Const GWL_STYLE = (-16)Enum TextInputStyles
     ES_UPPERCASE = &H8&
     ES_LOWERCASE = &H10&
     ES_NUMBER = &H2000&
    End EnumPublic Sub SetTextInputStyle(hWndTextControl As Long, InputStyle As TextInputStyles)
     Dim Style As Long
     Style = GetWindowLong(hWndTextControl, GWL_STYLE)
     Style = Style Or InputStyle
     SetWindowLong hWndTextControl, GWL_STYLE, Style
    End SubPrivate Sub optStyle_Click(Index As Integer)
     Select Case Index
      Case 0: SetTextInputStyle txtTest.hWnd, ES_UPPERCASE
      Case 1: SetTextInputStyle txtTest.hWnd, ES_LOWERCASE
      Case 2: SetTextInputStyle txtTest.hWnd, ES_NUMBER
     End Select
    End Sub