I have a VB6 form containing 3 command buttons.I want to create a shortcut to each control.For example when they press F1, command1 is executed,when they press F2 command2 is executed, when they press ESC command Exit is executed.
Printable View
I have a VB6 form containing 3 command buttons.I want to create a shortcut to each control.For example when they press F1, command1 is executed,when they press F2 command2 is executed, when they press ESC command Exit is executed.
Hi is not a proper title.
Set the keypreview property of your form to true and write thisVB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyF1 Call Command1_Click Case vbKeyF2 Call Command2_Click Case vbKeyF3 Call Command3_Click End Select End Sub
You don't need code for this. Place a standard command button on the form and enter 'Cancel' as its Caption property, and put Unload Me in its click event. Next, set the control's Cancel property to True. When Cancel Property is set to True VB executes the button's Click() event whenever you press the [Esc] key (as well as when you click it).Quote:
Originally Posted by engnouna
BTW:This is correct. Something like "Relate Function Keys To Command Buttons" would be more accurate.Quote:
Originally Posted by Shuja Ali