Click to See Complete Forum and Search --> : How to make TAB key work for RichTextBox Control ?


December 7th, 1999, 11:13 PM
Hi,

How can we make TAB key work for a Rich Text Box Control. I have set the properties TabStop = False, still it is not working.

Regards

RM

Chizl
December 7th, 1999, 11:45 PM
I know this looks stupid, but it is the only way I have found and noone has told me different..


Dim bTABHit as Boolean

private Sub RichTextBox1_KeyDown(KeyCode as Integer, Shift as Integer)
If KeyCode = 9 then
bTABHit = true

iStart = RichTextBox1.SelStart

If iStart = 0 then
RichTextBox1.Text = vbTab & RichTextBox1.Text
else
strText = RichTextBox1.Text
RichTextBox1.Text = mid(strText, 1, iStart) & vbTab & mid(strText, iStart + 1, len(strText) - iStart)
End If
RichTextBox1.SelStart = iStart + 1

End If
End Sub

private Sub RichTextBox1_LostFocus()
If bTABHit then
bTABHit = false
RichTextBox1.SetFocus
End If
End Sub




--
Chizl
chizl@NOSPAM.karland.com
http://www.chizl.com/

TimW
December 8th, 1999, 06:58 AM
Try this...

Private Sub RichTextBox1_KeyDown(KeyCode as Integer, Shift as Integer)

If KeyCode = vbKeyTab then

RichTextBox1.SelText = vbKeyTab
KeyCode = 0

End if

End Sub

Tim.