|
-
Jan 27th, 2012, 04:47 PM
#1
Thread Starter
Member
Detecting when the tab key is pressed in a textbox
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.
-
Jan 27th, 2012, 04:53 PM
#2
Re: Detecting when the tab key is pressed in a textbox
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.
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
-
Jan 27th, 2012, 04:55 PM
#3
Re: Detecting when the tab key is pressed in a textbox
Tried what code? you have displayed no code. I assume Tab is it a normal input key.
-
Jan 27th, 2012, 04:59 PM
#4
Thread Starter
Member
Re: Detecting when the tab key is pressed in a textbox
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.
-
Jan 27th, 2012, 05:03 PM
#5
Re: Detecting when the tab key is pressed in a textbox
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
Last edited by ident; Jan 27th, 2012 at 05:06 PM.
Reason: typo.
-
Jan 27th, 2012, 05:09 PM
#6
Thread Starter
Member
Re: Detecting when the tab key is pressed in a textbox
Thanks, ident; it worked great.
-
Jan 27th, 2012, 05:13 PM
#7
Re: Detecting when the tab key is pressed in a textbox
The TextBox has a Validating event specifically for this.
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|