04-02-2011, 03:58 PM
Hey guys. Here's a question for ya guys...
My coding selects an item from the list box and tries to color the words in the currently selected line, however, it often colors characters that come after the instance. Why is this happening?
Code:
Dim listbox1 As New ListBox
listbox1.Items.Add("<br/>")
Dim int As Integer = 0
Dim line As String = RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart)
For Each item In listbox1.Items
If RichTextBox1.Lines(line).Contains(item) Then
Dim instance As Integer = RichTextBox1.Find(item, RichTextBox1.SelectionStart - CInt(item.ToString.Length), RichTextBox1.SelectionStart)
If instance > 0 Then
RichTextBox1.SelectionStart = RichTextBox1.SelectionStart - CInt(item.ToString.Length)
RichTextBox1.SelectionLength = item.ToString.Length
RichTextBox1.SelectionColor = Color.Blue
End If
End If
Next
RichTextBox1.SelectionStart = ss
RichTextBox1.SelectionLength = sl
RichTextBox1.SelectionColor = Color.Black