VB建立快捷command按钮

来源:百度知道 编辑:UC知道 时间:2024/09/22 18:22:52
在command1的caption属性输入“确定&(E)”,command1变成:确定(E),运行时按下ALT+E就能激活“确定”按钮。
现在我要把他设计成只按E键就能激活“确定”按钮,怎么设计?

按E键激活“确定”,只能采用键盘按键监视的办法。具体如下:

Private Sub Command1_KeyPress(KeyAscii As Integer)
Form_KeyPress KeyAscii
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If UCase(Chr(KeyAscii)) = "E" Then
Command1_Click
End If
End Sub

把窗体的Keypreview属性设为True
然后加入以下代码

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyE Then
Command1_Click
End If
End Sub