如果用KeyPress事件,好像不能截获“del”键的KeyAscii 
    如果用MaskEdBox控件,会显示出固定的字符。
    有没有更好的方法?

解决方案 »

  1.   

    KeyPress包括F1-F12也是无法截获的使用 KeyDown 吧Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
       MsgBox KeyCode
    End Sub
      

  2.   


    KeyDown事件如何阻止键盘输入?达到KeyPress中KeyAscii = 0 那样的效果?
      

  3.   

    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
       '0-9的ASC值是48-57,A-Z大写是65-90,A-Z小写是97-122, KeyCode自动转为大写返回
       If (KeyCode >= 48 And KeyCode <= 57) Or (KeyCode >= 65 And KeyCode <= 90) Then
       Else
          KeyCode = 0 '不给值
          MsgBox ("输入无效,请重新输入!")
       End If
    End Sub
      

  4.   

    感谢cbm666,可是我试了一下,用KeyCode = 0好像并不能阻止键盘录入,非法字符还是能显示出来。
      

  5.   

    那直接子类化拦截wm_keydown就行罗.
      

  6.   

    这种问题,随便google一下,也能找到啊
    趁现在google还能用,快点儿用吧
      

  7.   

    Private Sub Text1_Change()
    For i = 1 To Len(Text1)
    S = Mid(Text1, i, 1)
    If S Like "[!0-9]" And S Like "[!A-Z]" And S Like "[!a-z]" Then
    Text1 = Replace(Text1, S, "")
    End If
    Next
    End Sub