Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB5,VB6
Expertise: Intermediate
Jun 16, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Let the user add tab characters to a RichTextBox control

If a form contains a RichTextBox control and other controls that are capable to receive the input focus, when the focus is on the RichTextBox and the user presses the Tab key to add a space, the focus will be moved to the following control in the tab order, and the tab character won't be added. The solution is check the KeyCode value of theKeyDown events: if it is vbKeyTab, you can programmatically add a tab space and set the KeyCode parameter to 0, to avoid the focus to be moved. Here's an example:

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyTab Then
        ' add the tab space
        RichTextBox1.SelText = vbTab
        ' set KeyCode to 0 to avoid the focus to be moved
        KeyCode = 0
    End If
End Sub
Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date