如何限制事件的发生?假设我不想在按backspace时发生textbox更改事件。
发布于 2009-10-14 18:44:26
在KeyPress事件中设置KeyAscii=0将导致按键被忽略。
Private Sub myTextBox_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyBack Then KeyAscii = 0
End Sub发布于 2009-10-14 18:53:23
由于Change事件不会向您传递上次按下的键的代码,因此您必须将其存储在KeyPress事件中,然后无论何时按下backspace键,都可以立即退出Change事件。
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 Subhttps://stackoverflow.com/questions/1568083
复制相似问题