Trapping the tab char

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
I have several textboxes on one form and am trying to trap the tab and Enter key presses and do a little processing before allowing the focus to shift to the next control. I have found Microsoft's page on the topic and it tells me I must override the "IsInputKey" function for the textbox control to trap the tab key. Their descriptions are so brief that I really don't grasp how this is done. Anybody feel like typing a quick demo to clarify ???
Thanx in advance....:)
 
Last edited:
Yea, it's a bit if a pain that the tab key doesn't raise the onkeydown/up events. But here's how you do it....

create a class level variable called preprocesskey and dimension it as integer

VB.NET:
[URL="http://www.vbdotnetforums.com/"][IMG]http://www.xmlfox.com/images/spacer.gif[/IMG][/URL]Protected Overrides Function ProcessKeyMessage(ByRef m As Message) As Boolean
[URL="http://www.vbdotnetforums.com/"][IMG]http://www.xmlfox.com/images/spacer.gif[/IMG][/URL]PreProcessKey = m.WParam.ToInt32
[URL="http://www.vbdotnetforums.com/"][IMG]http://www.xmlfox.com/images/spacer.gif[/IMG][/URL]End Function
[URL="http://www.vbdotnetforums.com/"][IMG]http://www.xmlfox.com/images/spacer.gif[/IMG][/URL]End Class

Then in your code you can just add...

VB.NET:
If PreProcessKey = Keys.Tab Then MsgBox("Tab is pressed!")
 
I played around with this code and could not seem to get it to trap the TAB key as coded above. Although, thanks to your lead, I found that overridding the "ProcessKeyEventArgs" DOES trap the tab key. Thanks for the help !
 
Last edited:
Back
Top