0
我尝试更改RichTextBox中某些单词的颜色,最后我发现了一个代码被剪掉了很多东西,但现在我遇到了问题。代码仅在我的RichTextBox中着色第一个“NULL”。在RichTextBox中着色某些单词
你能帮我找到解决办法吗?
感谢您的帮助!
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;
}
}
有人知道一个可能的方法来做到这一点吗?