2009-10-14 246 views

回答

4

在KeyPress事件中设置KeyAscii = 0会导致忽略按键。

Private Sub myTextBox_KeyPress(KeyAscii As Integer) 
    If KeyAscii = vbKeyBack Then KeyAscii = 0 
End Sub 
+0

这是取消激活文本框控件的键最简单的方法 – 2009-10-14 19:35:29

2

由于更改事件未通过你按下的最后一个键的代码,你必须存储在KeyPress事件,那么你就可以马上每次按下退格键退出更改事件。

Private keyCode As Integer 

Private Sub Text1_Change() 

    If (keyCode = vbKeyBack) Then 
    Exit Sub 
    Else 
    // do whatever it is you want to do in this event 
    // P.S.: I know this is the wrong comment syntax, 
    // but this code prettifier has a problem with 
    // VB6 comments 
    End If 

End Sub 

Private Sub Text1_KeyPress(KeyAscii As Integer) 

    keyCode = KeyAscii 

End Sub