Discussion Locked

Making Shortcut in VB6

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have Form In my VB program
and I want to make Shortcut from keyboard
to all the buuton in my from
i write the code for what i want in the
keydown Event in all the text box in the form
but that code sometimes work sometimes not work , so How Can I make shortcuts for all
the buttons in the Form with out any Problem

7 replies

by mark fenwick

I think what you require is to enable the KeyPreview feature on your form. That way any keypress events are processed by the form before the active control.

This way you only need examine the state of the keypress in one place.

You can enable keypreview in the form properties or at run time with 'me.kepreview = true'.

Hopw this helps

Mark

by khalid

thank you for your help
but Not this what I want , I mean
I want to make shortcut to all the button on the form using keys like F2,F3...

by whyong

Hi!! maybe you can try to put your code to onclick event and add a "&" in the caption of your button. for example, if you have a button's caption is "Print", when you put "&Print". key + "P" is the shortcut. it is normally what i do lah... hope it will help..

by khalid

thank you for your help
but Not this what I want , I mean
I want to make shortcut to all the button on the form using keys like F2,F3...

by mark fenwick

Hi,

I think my original reply is still valid, you just need to extend it a little!

The KeyPreview property is your answer, it means that you can check for function key presses before any controls (like the textbox control) get to process the key press event.

Cut and paste the code below into a form and you will see what I mean:

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyF9
MsgBox "You pressed F9!"
Case vbKeyF10
MsgBox "You pressed F10!"

End Select

End Sub

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

This discussion is closed to new replies.