-
how to color a word
HI everybody
I want to know how can i do to search a word in a richtextbox to count it and to color it , in yellow for example
this is my code , and i think it's incomplete and probably wrong
dim n as integer
dim t as string
for each t in richtextbox1.text
if t="hello" then
n=n+1
end if
next
'It doesn't works actually , can you help me
-
Re: how to color a word
Use the "SelectionStarts", "SelectionLength", "SelectionColor" properties
I think that's a good hit ;)
-
Re: how to color a word
Something like this should help you implement it your way:
Code:
Dim rtbText As String = RichTextBox1.Text
Dim ColoredString As String = "hello" 'it is case sensitive
Dim Index As Integer
Index = rtbText.IndexOf(ColoredString)
Do While Index > 0
Index = rtbText.IndexOf(ColoredString, Index + 1)
If Index <> -1 Then
RichTextBox1.Select(Index, ColoredString.Length)
RichTextBox1.SelectionColor = Color.Yellow
End If
Loop