vb 热键定义

来源:百度知道 编辑:UC知道 时间:2024/05/13 03:14:11
如何定义 按下F9 相当与点击下 按钮1
2楼的好用,但是必须是窗体获得焦点时才有效,有没有一直有效的?

Private Sub Form_Load()
KeyPreview = True
End Sub
Private Sub Command1_Click()
MsgBox "单击了Command1或按下F9"
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 120 Then Command1_Click
End Sub

Private Sub Command1_Click()
Print "你要发财啦!!!"
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = &H78 Then Command1_Click
End Sub

Private Sub Form_Load()
KeyPreview = True
End Sub

Private Sub Command1_Click()
MsgBox "helloworld!"
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call Command1_Click
End If
End Sub

其中的13是回车键,F9是哪个数不知道,LZ自己试一下吧