Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Key in Rich text format Control

Status
Not open for further replies.

Robertge

Programmer
Jul 4, 2002
18
IT
Hi,
I'm working with a Rich text format control and when I press the tab key(or shift + tab key), I want to indent/outdent all the selected text (to right or to left) ALSO IF I SELECT MORE THEN ONE LINE.

I realize the following code but does not work exactly.

My problems are:
1)after I examined and substituted the seltext of richtext (character by character) going out from the KeyDown event, the richtext receive my text AND (of course) also the key tab.
How I can avoid to "send" also the tab key to the rich text?

2) Using a string to substitute the text, I will loose the different format of every line/word (like bold, color, etc)
I thought to use another rich text box but... How could I work character by character of every line of the seltext in RTF???

OK, Thanks


Private Sub rtfBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
If rtfBox1.SelLength > 0 Then
Dim t, t2 as String
Dim Char As String * 1, Char_Prec As String * 1
Dim i_s As Long, i_l As Long, I As Long, len1 As Long

'save seltext and len
i_s = rtfBox1.SelStart
i_l = rtfBox1.SelLength
t = rtfBox1.SelText
len1 = Len(t)
For I = 1 To len1
If Shift = 0 Then 'no shift
Char = Mid(t, I, 1)
If I = 1 Then
t2 = Chr(9) & Char
ElseIf Char = vbCrLf Then
t2 = t2 & Char & Chr(9) 'insert tab
'ElseIf Char = vbCr Then
' t2 = t2 & Char & Chr(9) 'insert tab
ElseIf Char = vbLf Then
t2 = t2 & Char & Chr(9) 'insert tab on linefeed
Else
t2 = t2 & Char
End If
Else
If Char = Chr(9) Or I = 1 Then
If I = 1 Then
If Char = Chr(9) Then
t2 = t2 'remove tab
End If
ElseIf Char_Prec = vbCrLf Then
t2 = t2 'remove tab
'ElseIf Char = vbCr Then
' t2 = t2 'remov tab
ElseIf Char_Prec = vbLf Then
t2 = t2 'remove tab after linefeed
Else
t2 = t2 & Char
End If
End If
Char_Prec = Char
End If
Next
rtfBox1.SelText = t2

'HOW block the key pressed???????


'reset seltext selection
rtfBox1.SelStart = i_s
rtfBox1.SelLength = Len(t2)
rtfBox1.SetFocus
End If
End If
end sub
 
Use SelLength = 0 to insert a character or characters at a given SelStart and do not include previous text. Use SelLength=1 and SelText="" to delete a character. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top