Results 1 to 5 of 5

Thread: Trapping Arrow Keys

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Location
    Brisbane, Australia
    Posts
    34

    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

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  3. #3
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    vb.net compiler says "Return" not decleared.

  4. #4
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Oh sorry,
    I just noticed that I have typed some of "Return"s as "Retrun" in the above code.

  5. #5
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width