When you use the Rich Textbox control on a form, you'll often want to
let users add tabs to their input. If the Rich Textbox is the only
control on the form, then pressing the [Tab] key inserts the requested
tab space into the text. Most likely, however, you'll have more than one
control on the form, in which case pressing the [Tab] key moves the
focus from the Rich Textbox to another control.
To prevent this behavior, you could simply set each control's TabStop
property to False. This prevents users from tabbing between ANY
controls--but does let them enter tabs into the Rich Textbox.
Chances are, though, you want to give users the ability to tab between
controls AND enter tabs in the Rich Textbox. Fortunately, VB provides
the tools for you to do so in the Rich Textbox control's KeyDown()
event.
As you probably know, the Rich Textbox fires this event when a user
presses a key while the control has the focus. Like all KeyDown()
events, you can use code to determine which key the user pressed and
react accordingly. To capture the Tab key and insert a tab space into
the Rich Textbox control's edit area, we could use the following:
Private Sub RichTextBox1_KeyDown(KeyCode _
As Integer, Shift As Integer)
Dim mblnTabPressed As Boolean
mblnTabPressed = (KeyCode = vbKeyTab)
If mblnTabPressed Then
RichTextBox1.SelText = vbTab
KeyCode = 0
End If
End Sub
Add tab spaces in the RichTextBox
By ElementK Journals, published on 14 Jul 2001
| Filed in
You might also like...
VB 6 forum discussion
-
CorelDRAW VBA: cdrTraceLineDrawing FAILS, producing single linear path instead of Centerline trace?
by dancemanj (0 replies)
-
client/server application using activex
by beautifulheart (0 replies)
-
System Error &H8007007E. The specifed module could not be found.
by swiftsafe (5 replies)
-
Invitation to take part in an academic research study
by researchlab (0 replies)
-
Send SMS with SMPP
by mmahmoud (0 replies)
VB 6 podcasts
-
Stack Overflow Podcast: Podcast #45 – Keeping it Sharp
Published 7 years ago, running time 0h54m
Our guest this week is Eric Lippert – language architect extraordinaire and famous for all his work at Microsoft in developing their languages Eric joined Microsoft right out of college and was originally working on VB It’s time for everyone’s favorite game: Name the Worst Feature of that Microso.
Comments