-
Aug 8th, 2020, 01:59 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] e.keychar = chr(9) not working
why does the tab not work?
Code:
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Chr(13) Or e.KeyChar = Chr(9) Then
'e.KeyChar = Chr(8)
Form1.words.Add(TextBox2.Text)
TextBox2.Text = ""
End If
End Sub
Thanks
George
-
Aug 8th, 2020, 02:13 PM
#2
Re: e.keychar = chr(9) not working
Because the Tab key doesn't trigger the KeyPress event.
-
Aug 8th, 2020, 02:14 PM
#3
Thread Starter
Hyperactive Member
Re: e.keychar = chr(9) not working
what does the tab key trigger?
-
Aug 8th, 2020, 02:28 PM
#4
Re: e.keychar = chr(9) not working
Originally Posted by georgesutfin
what does the tab key trigger?
It triggers moving the focus from one control to the next control in the tab order.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Aug 8th, 2020, 02:30 PM
#5
Re: e.keychar = chr(9) not working
Hello
Use PreviewKeyDown event
Code:
' By default, KeyDown does not fire for the tab key
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox1.KeyDown
Select Case (e.KeyCode)
Case Keys.Tab
MsgBox("test")
End Select
End Sub
' PreviewKeyDown is where you preview the key.
' Do not put any logic here, instead use the
' KeyDown event after setting IsInputKey to true.
Private Sub TextBox1_PreviewKeyDown(ByVal sender As Object, ByVal e As PreviewKeyDownEventArgs) Handles TextBox1.PreviewKeyDown
Select Case (e.KeyCode)
Case Keys.Tab
e.IsInputKey = True
End Select
End Sub
Last edited by Delaney; Aug 8th, 2020 at 04:49 PM.
Reason: add example from docs.microsoft.com
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Aug 8th, 2020, 02:32 PM
#6
Thread Starter
Hyperactive Member
Re: e.keychar = chr(9) not working
Thank you so much Delaney that is what I was looking for
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
|