PDA

Click to See Complete Forum and Search --> : Trapping Arrow Keys


aliddle
Nov 15th, 2002, 12:02 AM
Hi All,

It appears that in VB.Net Microsoft (In their infinite wisdom) has decided to make arrow keys act like the TAB key. In my application I need to know when the arrow keys are pressed when one of my UserControls has focus. Unfortunately, The arrow keys don't even raise the KeyDown event for my UserControl.

How do I get around this little problem?

Alan Liddle

Lunatic3
Nov 15th, 2002, 08:03 AM
You should override the IsInputKey function of the control. Imagining that you have a textbox as a contorl this my help

Public Class mytextbox
Inherits System.Windows.Forms.TextBox

Protected Overrides Function IsInputKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
Select Case keyData
Case Keys.Left
MsgBox("LEFT") ' Any code can go here
Return True
Case Keys.Right
MsgBox("RIGHT") 'any code can go here
Retrun True
Case Keys.Up
MsgBox("UP") 'any code can go here
Retrun True
Case Keys.Down
MsgBox("DOWN") 'any code can go here
Retrun True
End Select
Return MyBase.IsInputKey(keyData)
End Function

ProgrammerJon
Feb 2nd, 2003, 04:11 PM
vb.net compiler says "Return" not decleared.

Lunatic3
Feb 2nd, 2003, 04:40 PM
Oh sorry,
I just noticed that I have typed some of "Return"s as "Retrun" :( in the above code.

ProgrammerJon
Feb 2nd, 2003, 06:27 PM
Thanks.