I'm trying to select/highlight certain parts of my RTB-Lines. Splitted by ":" i want to have both parts to have each their own selectioncolor.
This is what my RTB-Text looks like:
Key1:Value1
Key2:Value2
Key3:Value3
Key4:Value4
Key5:Value5
...
This is my code so far:
For i As Integer = 0 To rtbxPreview.Lines.Count - 1
Dim currStartIndex As Integer = rtbxPreview.Text.IndexOf(rtbxPreview.Lines(i))
rtbxPreview.Select(currStartIndex, rtbxPreview.Text.IndexOf(":", currStartIndex) - currStartIndex)
rtbxPreview.SelectionColor = Color.DeepSkyBlue
Dim currLastIndex As Integer = rtbxPreview.Text.LastIndexOf(rtbxPreview.Lines(i))
rtbxPreview.Select(currLastIndex, rtbxPreview.Text.LastIndexOf(":", currLastIndex) - currLastIndex)
rtbxPreview.SelectionColor = Color.Purple
Next
It works, but not all the time. Click here to see the results after that. As you can see on the screenshot, that code above somehow skipped the selection on "Value4" and "Key7", leaving them on the default ForeColor. How can that happen, what am i doing wrong above?
Appreciated any kind of Help!
