Jeff Certain
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.KeyPr essEventAr gs) Handles MyBase.KeyPress
Select Case e.KeyChar
Case "1"
Case "2"
Case "3"
End Select
End Sub
Thanks!
Jeff
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.KeyPr
Select Case e.KeyChar
Case "1"
Case "2"
Case "3"
End Select
End Sub
Thanks!
Jeff
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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