Capture the TAB key


I have written a couple of apps, all have standard text boxes or Rich Text boxes. I have never been able to figure out how to capture the TAB key for use DURING DATA INPUT to these boxes.
The books say that the TAB is generally not available but word processing type programs use it all the time. HOW can I get this key (or fake something) so as to insert either the tab character or X number of spaces into my text box.
I have tried Subclassing the keyboard routine and have had some success. Sometimes I can capture the tab key just fine but not 100% of the time.

If you enjoyed this post, subscribe for updates (it's free)

How to trap tab key

I am using two text boxes (Text1 and Text2). Text1 has tab index zero and Text2 has one. What I want if anybody press tab key on Text2 the focus will go on Text1. Can any body help me.

Capture the TAB key

I hope that this helps as I also beat my head on a wall for a answer to the TAB problem.
NOTE:
This works for a RTB box - I have not tried the same code for a standard text box.
----------------------
It has been a process to figure out how to get the TAB key to work all the time within a RTB control. In the official manual discussion on the RTB control there is mention of the following routine.

In the RTB GOTFOCUS event the tab stop property for all of the controls on the form are turned OFF. This means that the tab works only within the rtb control.

In the RTB LOSTFOCUS event the tab stop property for all of the controls on the form are turned BACK ON. This returns Tab functionality back to normal

Private Sub rtbNotes_GotFocus()
Dim mControl As Control

'Ignore errors for controls without a tabstop property
On Error Resume Next
'Switch OFF the tabstop property
For Each mControl In Controls
mControl.TabStop = False
Next mControl

End Sub 'rtbNotes_GotFocus()

Private Sub rtbNotes_LostFocus()
Dim mControl As Control

'Ignore errors for controls without a tabstop property
On Error Resume Next
'Switch ON the tabstop property
For Each mControl In Controls
mControl.TabStop = True
Next mControl

End Sub 'rtbNotes_LostFocus()

------------------------------

TAB key

hay gays.. :D
paste this code in your textbox_keydown event and then use CTRL + TAB
Sebastjan

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim myText As String
Dim StartAt As Single
If KeyCode = KeyCodeConstants.vbKeyTab And Shift = 2 Then
StartAt = Text1.SelStart
myText = Left$(Text1.text, StartAt) + vbTab + Mid$(Text1.text, StartAt + 1)
Text1.text = myText
Text1.SelStart = StartAt + 1
Text1.SetFocus
End If
End Sub

Ref: Textbox for Arabic text facility

But what does Textbox for Arabic text facility have to do with Capture the TAB key?

You are better of making a new topic.

Keith
www.martin2k.co.uk/forums/

I've been programming with VB for 13 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning

Textbox for Arabic text facility

I have developed a software in VB 6 the software works on both languages Arabic and English
and I have Windows XP Operating System . When I Enter text in textbox , the default Eng laugange is working and I want when I gotfocus on textBox the Regional Language Automatically change in Arabic

for this I need your Help and sulotion

Capture the TAB key

Well if your using TextBoxes and when you press the Tab key you want the focus to be switched to the next TextBox and all you have to do its set the TabIndex for the TextBoxes at DesignTime.

So the first TextBox you want to use will have a TabIndex of 0 (zero) the next one will be 1 then 2 etc.

You can set this TabIndex to any control.

I've been programming with VB for 14 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.