我想在输入筐中输入内容的时候屏蔽一些字符,不知道能采用什么方法,而且我还有好几个按扭,在点击后,都需要屏蔽输入筐中的内容,怎么来实现?请各位帮忙。

解决方案 »

  1.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    if keyascii=13 then    '你要屏蔽的ASCII码
    keyascii=0             'keyascii=0就屏蔽了
    End Sub
      

  2.   

    呵呵~ 今天刚好我讲到这个!If KeyAscii = 8 Then
    KeyAscii = 8
    ElseIf KeyAscii < 46 Or KeyAscii > 58 Then KeyAscii = 0
    End If这代码保证你只能输入0-9 + 小数点 + 退格可用------------
    欢迎加入cike技术交流群: 16874787
      

  3.   

    在使用KEYPRESS的时候不是先要使窗体的keypreview属性为true 吗?那在什么位置添加?
      

  4.   

    功能最完善的:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 46 Then
        If InStr(Text1.Text, ".") <> 0 Then
            KeyAscii = 0
            Exit Sub
        Else
            KeyAscii = 46
            Exit Sub
        End If
    End If
    If KeyAscii = 8 Then
    KeyAscii = 8
    ElseIf KeyAscii < 48 Or KeyAscii > 58 Then KeyAscii = 0
    End IfEnd Sub
      

  5.   

    KEYPRESS和form1.keypreview是没有直接关系 的