-
Trapping Arrow Keys
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
-
You should override the IsInputKey function of the control. Imagining that you have a textbox as a contorl this my help
Code:
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
-
vb.net compiler says "Return" not decleared.
-
Oh sorry,
I just noticed that I have typed some of "Return"s as "Retrun" :( in the above code.
-