Vb6 Visual basic 6事件

Vb6 Visual basic 6事件,vb6,Vb6,如何限制事件的发生?假设我不希望在按backspace时发生textbox更改事件。在KeyPress事件中设置KeyAscii=0将导致忽略KeyPress Private Sub myTextBox_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyBack Then KeyAscii = 0 End Sub 在按键事件中设置KeyAscii=0将导致忽略按键 Private Sub myTextBox_KeyPress(KeyAsci

如何限制事件的发生?假设我不希望在按backspace时发生textbox更改事件。

在KeyPress事件中设置KeyAscii=0将导致忽略KeyPress

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

在按键事件中设置KeyAscii=0将导致忽略按键

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

由于更改事件不会向您传递上次按下的键的代码,因此您必须将其存储在KeyPress事件中,然后您可以在按下backspace键时立即退出更改事件

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

由于更改事件不会向您传递上次按下的键的代码,因此您必须将其存储在KeyPress事件中,然后您可以在按下backspace键时立即退出更改事件

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

这是停用textbox控件键的最简单方法这是停用textbox控件键的最简单方法