VB 键盘事件

Keypress,KeyUp,KeyDown事件响应的先后顺序?最好举个例子先~
2024-11-15 07:46:29
推荐回答(1个)
回答1:

顺序为
keydown
keyup
keypress
例:在窗体上建立一个文本框TextBox1,然后增加以下的事件处理代码;
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Print 1
End Sub

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Print 2
End Sub

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Print 3
End Sub
然后运行窗体时在TextBox1文本框中敲一次键盘后,输出结果分别为1 2 3的顺序