Link to home
Start Free TrialLog in
Avatar of Jeff Certain
Jeff CertainFlag for United States of America

asked on

VB2003 Windows Form KeyPress event handler not firing

I'm got a Windows application pretty much finished. One of the last tasks is to allow the user to fire buttons using keypresses. I thought this would be fairly trivial. I was able to get a new Windows app with an empty form to fire this event.

However, when I try to implement a KeyPress handler in my current application, the event doesn't seem to fire. Does anyone have any ideas why this might be?

Here's the handler:
      Private Sub Main_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
            Select Case e.KeyChar
                  Case "1"
                  Case "2"
                  Case "3"
            End Select
      End Sub

Thanks!

Jeff
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
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 Jeff Certain

ASKER

planocz,

Well, I had determined that the reason nothing was firing was that the focus was being set to a button... and so I had to trap the Keypress event for EVERY control on my form. I like your approach WAY better. :):)

BTW: Works fine for a non-MDI form, too.

Thanks!

Jeff