Link to home
Start Free TrialLog in
Avatar of indy500fan
indy500fan

asked on

Handle keydowns on a form with tab pages....

Friends,

I have a form with 2 TabPages and I want to be able to press the F keys.  However, when I try and push F9 for example, the Handles MyBase.KeyDown is never reached.

What's going on?

Thanks in advance!

Best Regards,
Eric
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        'When the function keys are pressed, FuncKeysModule is called.
 
        If e.KeyValue = Keys.F1 Or Keys.F2 Or Keys.F3 Or Keys.F4 Or Keys.F5 Or Keys.F6 Or Keys.F7 Or Keys.F8 Or Keys.F9 Or Keys.F10 Or Keys.F11 Or Keys.F12 Then
            FuncKeysModule(e.KeyValue)
            e.Handled = True
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Hawkvalley1
Hawkvalley1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jorge Paulino
You need to repeate the e.KeyValue for all the conditions:
If e.KeyValue = Keys.F1 Or e.KeyValue = Keys.F2 Or e.KeyValue = Keys.F3 Or ...
Or use a Select Case statement:

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        'When the function keys are pressed, FuncKeysModule is called.
 
        Select Case e.KeyValue
            Case Keys.F1 To Keys.F12
                FuncKeysModule(e.KeyValue)
                e.Handled = True
        End Select
 
    End Sub

Open in new window

Avatar of indy500fan
indy500fan

ASKER

Hawkvalley1,

Yep that worked!

JPaulino,  I agree, and I have that part worked out, but the control went to the tabpages first and not the form, so I could never even test the conditions; which is the root of my question.

Thanks,
Eric
Exactly what I needed.