Intercepting the TAB key in a textbox

I need to use the TAB key to feed the string "0.5" into a textbox and then move on to the next control, as though the user has typed "0.5" (and then pressed TAB). I see the solution suggested is to override IsInputKey but for the life of me I can't work how to apply the method - every way I try doesn't trap the TAB key. How/where do I set the override to get the TAB key identified by KeyDown It certainly doesn't work if I use -

Dim NewTB As New TextBox

Me.Controls.Add(NewTB)

AddHandler NewTB.KeyDown, AddressOf KeyIsDown

etc. and then...........

Private Sub KeyIsDown(ByVal o As [Object], ByVal e As KeyEventArgs)

Dim keyData As Keys

Dim returnValue As Boolean

returnValue = Me.IsInputKey(keyData)

' . . . . the TAB key doesn't pass by here ... why

End
Sub

Please can someone throw some light here Thanks!



Answer this question

Intercepting the TAB key in a textbox

  • DSV-Alex

    a couple of suggestions

    1. use the built in event declaration when you can

    2. use the keyup event verses the key-down event when checking keystrokes

    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp

    If e.KeyData = Keys.Tab Then

    dosomething...

    End If

    End Sub



  • Intercepting the TAB key in a textbox