i try to change the color of certains words in a RichTextBox, finally i found a code snipped wich help me alot, but now i have a problem. The code only colours up the first "NULL" in my RichTextBox.
Can you help me to find a solution ?
Thanks for your helping!
private void searchWord()
{
String search = "NULL";
TextPointer text = RTBAuftrag.Document.ContentStart;
while (true)
{
TextPointer next = text.GetNextContextPosition(LogicalDirection.Forward);
if (next == null)
{
break;
}
TextRange txt = new TextRange(text, next);
int indx = txt.Text.IndexOf(search);
if (indx > 0)
{
TextPointer sta = text.GetPositionAtOffset(indx);
TextPointer end = text.GetPositionAtOffset(indx + search.Length);
TextRange textR = new TextRange(sta, end);
textR.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Red));
}
text = next;
}
}
Does somebody know a possible way to do this ?