Private Sub Text1_KeyPress(KeyAscii As Integer) MsgBox KeyAscii KeyAscii = 0 End Sub
好象不对呀!我用以下代码: Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 9 Then
MsgBox "tab" End If End Sub但没有 弹出 “tab”呀???
Option Explicit'得用这个事件 Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 9 Then MsgBox "tab" End If End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) MsgBox "125" If KeyCode = 9 Then MsgBox "tab1255" End If End Sub这段代码根本不运行呀! 另外,我要的是某控件比如 textbox 中获得键盘的上被按下的 键的 code 和 name ???
Option ExplicitPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) MsgBox "125" If KeyCode = 9 Then MsgBox "tab1255" End If End Sub
既然只是在tab键上跳走 那它跳走的时候text失去焦点,我们可以把这个直接显示“msgbox 9 ”呀 然后让text重新获得焦点Private Sub Text1_KeyPress(KeyAscii As Integer) MsgBox KeyAscii End SubPrivate Sub Text1_LostFocus() MsgBox 9 Text1.SetFocus End Sub
MsgBox KeyAscii
KeyAscii = 0
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
MsgBox "tab"
End If
End Sub但没有 弹出 “tab”呀???
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
MsgBox "tab"
End If
End Sub
MsgBox "125"
If KeyCode = 9 Then
MsgBox "tab1255"
End If
End Sub这段代码根本不运行呀!
另外,我要的是某控件比如 textbox 中获得键盘的上被按下的 键的 code 和 name ???
MsgBox "125"
If KeyCode = 9 Then
MsgBox "tab1255"
End If
End Sub
KeyCode = 9 是检测不到呀!但是 8, 13 都可以的!
很奇怪!!
tab是9 控制字符是HT
1 在接受光标的控件上 处理事件
2 用API 检测 什么时候按tab
MsgBox KeyAscii
End SubPrivate Sub Text1_LostFocus()
MsgBox 9
Text1.SetFocus
End Sub
比如,按下 回车键 时,它的 代码是 “13 ”,键名 是 “enter”