In a textbox i can see when RETURN is pressed , but when i check on the TAB key it does not work Help me Plzzz.

Dim handler As KeyEventHandler

Private Sub Orderinvoer_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler werkorderTB.KeyDown, handler
end sub

 Private Sub werkorder_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles werkorderTB.KeyDown
        REM Watch the return Key
        If e.KeyCode = Keys.Return Then
            MsgBox("return ")
        End If
 End Sub

This works !
But when i change return to Tab , it wont work

You need to set TabStop = False on every control in your form if you want the tab key to register in the KeyDown event.
If even a single control that can receive focus has its TabStop property set to true the Tab key wont register.

Hi Ryshad,
I am experiencing similar problem with Ulukay.

I follow your suggestion and tested it out. I have set all the textbox control properties TABSTOP = FALSE.

At a particular textbox control KEYDOWN event for testing purpose I created this script

Private Sub txtDebtorId_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDebtorId.KeyDown
  IF  e.Keycode = Keys.Tab then
        messagebox,show ("I am TABSTOP and Working")
  End IF
End Sub

Surprising it's not working at all.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You need to set TabStop = False on every control in your form if you want the tab key to register in the KeyDown event.
If even a single control that can receive focus has its TabStop property set to true the Tab key wont register.

Well turned them all off.
And after i hit the tab key , my cursor disapears.
But still now Keydown event.

helpppp

@LennieKuah: was "Messagebox,/B]show" a typo here or in your code? should be a '.' not ','. Also, you need to remove the tabstop from all controls that can recieve tabstop, not just the textboxes.

@ulukay: firstly, have you made sure all controls that have the tabstop property have been set to false. Also, try putting a breakpoint in the KeyDown event to see if it fires when you hit Tab.

@LennieKuah: was "Messagebox,/B]show" a typo here or in your code? should be a '.' not ','. Also, you need to remove the tabstop from all controls that can recieve tabstop, not just the textboxes.

@ulukay: firstly, have you made sure all controls that have the tabstop property have been set to false. Also, try putting a breakpoint in the KeyDown event to see if it fires when you hit Tab.

Thanks ,
But no it doesnot fire .
And im sure i checked all !
Jack

Hi All Helpers,
Thanks to all of you for sharing your knowledge and experiences with me. I have set all the Command buttons and TextBoxes TABSTOP property = FALSE and now my script is working.

Thanks and Merry Christmas and Blessed Happy New Year.
This FORUM is awesome with very generous helpers.

in keypress event:

if e.keychar = chr(9) then msgbox("TAB")
if e.keychar = chr(13) then msgbox("ENTER")

You should probably override ProcessCmdKey() to handle your logic:

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    If (keyData = Keys.Tab) And (Me.ActiveControl Is TextBox1) Then
      MessageBox.Show("return")
      Return True 'Stops the tab from being processed
    Else
      Return MyBase.ProcessCmdKey(msg, keyData)
    End If
  End Function

Hi SkNake,

Thank you for your sample script. I will try it out in order to learn and understand how it works. Once I got it working, I will get back to you and paste the working script here to share it with other newbies who may have similar problem.


SkNake,
How do I access to this Override Function ProcessCmdKey ?

Thanks, SkNake.

Edited 6 Years Ago by LennieKuah: n/a

This article has been dead for over six months. Start a new discussion instead.