CodeItBetter Programming Another VB Programming Blog

How to set color between two characters in RichTextBox. Like changing the color to Green between < and >

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'Controls - How to set color between two characters in RichTextBox. Like changing the color to Green between < and >
Public Sub ChangeColorInRichTextBoxBetweenTwoChars(ByVal str1stChar As String, _
    ByVal str2ndChar As String)
    Dim lPos As Long, lEnd As Long
    Do
        lPos = InStr(lEnd + 1, RichTextBox1.Text, str1stChar)
        If lPos Then
            lEnd = InStr(lPos + 1, RichTextBox1.Text, str2ndChar)
            If lEnd Then
                RichTextBox1.SelStart = lPos
                RichTextBox1.SelLength = lEnd - lPos - 1
                RichTextBox1.SelColor = vbGreen
            End If
        End If
    Loop Until lPos = 0 Or lEnd = 0
End Sub
 
Private Sub Command1_Click()
    Call ChangeColorInRichTextBoxBetweenTwoChars("<", ">")
    Call ChangeColorInRichTextBoxBetweenTwoChars(ChrW$(34), ChrW$(34))
End Sub
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.