KeyPress 和KeyDown
下面是一个combobox的keydown事件和一个keypress事件,我想问下,这代码到底是表达的什么意思
Private Sub cboDevId_KeyDown(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyEventArgs) Handles cboDevId.KeyDown
Dim KeyCode As Short = eventArgs.KeyCode
Dim Shift As Short = eventArgs.KeyData \ &H10000
Dim KeyAscii As New Object
On Error GoTo cboDevId_KeyDownErr
If KeyAscii <> 8 Then KeyAscii = 0
Exit Sub
cboDevId_KeyDownErr:
ShowErrorBox("frmGvApp13.cboDevId_KeyDown")
End Sub
‘-------------------------------------------------
Private Sub cboDevId_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles cboDevId.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
On Error GoTo cboDevId_KeyPressErr
'KeyAscii = 0
If KeyAscii <> 8 Then KeyAscii = 0
GoTo EventExitSub
cboDevId_KeyPressErr:
ShowErrorBox("frmGvApp13.cboDevId_KeyPress")
EventExitSub:
eventArgs.KeyChar = Chr(KeyAscii)
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
[解决办法]
屏蔽退格键之外的按键