I have tried the KeyDown, KeyPress and KeyUp events but they don't capture the pressing of the Tab key. Anyone know of how to capture the event when the Tab key is pressed?
Yes, the windows handlers grab the tab key and move the cursor to the next control. The KeyPress event does not get fired for tab when tabbing from one textbox to the next. I would like to perform a separate action (close a list box) when the tab key is pressed and then have it continue as normal to the next control. I solved the problem in my program by using the Leave event and in this case it doesn't matter whether it's leaving the textbox because the tab was pressed or leaving the textbox because of a mouse click elsewhere but I still have not been able to capture just the tab key.
I searched everywhere I could think of and couldn't find the syntax for overriding the ProcessDialogKey method. I finally looked at online help and it turned out to be really simple.
This method intercepts and processes keys that are not intercepted by the KeyPress event.
base.ProcessDialogKey(keyData) takes the keyData and processes it as if it had not been intercepted. For example with this override in place if you press the tab key when your cursor is in a text box the override method will fire, the MessageBox will show and then the base.ProcessDialogKey will continue with normal operation of the tab moving you to the next control. If you press the shift key, as you would expect the override fires but the base process leaves the cursor in the text box.
This all seems so simple once you know it and such a mystery when you don't.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.