Sunday, January 11, 2009

Detecting Arrow keys on a windows form application using VB.NET

Handling arrow keys on a VB windows form is a pain until you find a solution that works according to your needs:) Well I posted this coz I got excited having solved a problem I had with detecting the arrow keys in VB.NET. I've been struggling to detect the arrow keys on a windows application form that I was designing in VB 2008.

The form contained a TabControl and needed to detect the keys only on TabPage1. Since there were many other controls on the form I had to use an overriding function.

i.e:

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _ ByVal keyData As Keys) As Boolean

 ' detect which key is pressed and perform some action

End Function

The problem is that TabPage2 contained a textbox and would allow me to enter only a single character. To continue typing into the textbox I needed to click in the textbox and type the next character. To overcome this problem I needed to check which TabPage had the focus. But the problem was where to check the focus.

Download my code to find out how I solved my problem: http://www.mediafire.com/?wnw3zduymtj Hopefully someone finds this post useful.

No comments:

Post a Comment