I thought it was simple but i guess it's not...
How do I detect when the tab key is pressed in a textbox?
I've tried the following code in KeyPress, KeyDown, Leave, etc. events but the tab is not detected.
Printable View
I thought it was simple but i guess it's not...
How do I detect when the tab key is pressed in a textbox?
I've tried the following code in KeyPress, KeyDown, Leave, etc. events but the tab is not detected.
Are you asking because you want your textbox to accept a tab press rather than change focus? If so set the TextBox's AcceptsTab property to True.
Tried what code? you have displayed no code. I assume Tab is it a normal input key.
Here is the code..
If (e.KeyCode = Keys.Tab) Then
MessageBox.Show("Tab Key")
End If
My default focus is on a textbox which accepts only numeric values. I enter 123456 and hit the tab key to move over to next textbox control. When tab key is hit; I want to run some validations before moving over to the next textbox control.
vb Code:
Private Sub TextBox1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles TextBox1.PreviewKeyDown If e.KeyData = Keys.Tab Then e.IsInputKey = True End If End Sub Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyData = Keys.Tab Then Debug.WriteLine("Hello tab key") End If End Sub
Thanks, ident; it worked great.
The TextBox has a Validating event specifically for this.