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?
The tab key is ASCII character 9. The KeyPress event will not capture it when exiting a textbox unless the AcceptsTab=true and Multiline=true but then tab does not actually leave the textbox, it becomes part of the text. I was able to solve the programming problem by using the Leave event which fires whether you are pressing tab or clicking in another control when leaving the textbox. This worked fine for the purpose I needed but I did not specifically capture the tab key. The tab is being used by the windows handler to move from control to control. I just wanted to capture it, do something, and then have the cursor continue to the next control. I have been advised that overriding the ProcessDialogKey method will give me access to all the keys that are typed but I don't know the proper syntax to use that approach yet. Do you know the syntax for overriding the ProcessDialogKey method?
I think all you have to do to override any function/sub is just include the word "override" when declaring it
so like:
Public Override ProcessDialogKey()
But I havn't really looked into that much. We tried overriding the dispose method to try and take control of the garbage control, but we didn't have any success with it.
I would expect the ProcessDialogKey() to have at least one argument, the key that is being processed. If I find the answer I'll post here for all of us.
Christmas was great, one of the best for us. Everyone in the family was happy. The company I am working for is purchasing a new laptop for me complete with docking station and duel monitors, 48 Gig HD, DVD, etc. Pretty cool getting a development laptop. That's going to make my Christmas! Hope you had a good one too.
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.
I can see how that can work for a VB app on the client computer, but what about an ASP.NET page where a keystroke is a client side event? Wouldn't you need to have the page post back to the server each time a key is pressed to see if it was the tab key or not?
Also, I didn't catch why the tab key would trigger it to fire, but the shift key wouldn't.
ARRGHH! Me thinks I've created MORE mysteries for us to solve! Hey, btw, do you do most of your coding with C# or VB?
Sorry Jack, right now I am writing a desktop application and I was very excited about overriding a method. It was my first override. Doesn't take much to get me excited. I don't know how I would or if I could accomplish in a web page what I have written for the desktop. There is some overlap between Windows Forms and ASP.NET that makes this override concept useful because of the server side capabilities of ASP.NET but I should have qualified that I was not writing an ASP.NET page. Thanks for creating a new mystery of getting the custom user input control I have for the desktop to work with all the same features in a browser.
Both the tab key and the shift key do fire the overrided ProcessDialogKey method. My test showed that the tab key continued with normal behavior being processed with the base.ProcessDialogKey(keyData) taking the cursor to the next control while the shift key also continued with normal behavior after being processed with the base.ProcessDialogKey(keyData) by remaining in the text box. If the base.ProcessDialogKey(keyData) is not included in the override ProcessDialogKey(Keys keyData) method then the override ProcessDialogKey(Keys keyData) consumes the keystrokes and the tab does not move the cursor to the next control and I suspect the shift key is consumed as well.
I do all of my coding in C#. I have done some VB programming over the years but my primary language for many years was C. Of course all previous languages were procedural and this oop is new and exciting to me. I can interpret VB if I have to but I have settled on C# as my primary language.
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.