簡體   English   中英

如何從文本中的給定位置獲取字符的顏色?

[英]How can I get the color of a character from a given position in a text?

我基本上想檢查文本中給定位置的字符是否是某種顏色。 例如

if(character.inAposition == blue){
   change characters color
}

這就是我最初更改文字顏色的方式

TextPointer start = position.GetPositionAtOffset(indexInRun);
TextPointer end = start.GetPositionAtOffset(word.Length);
TextRange rangeText = new TextRange(start, end);
rangeText.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);

其中indexInRun是與“ word”匹配的任何子字符串的起始索引

您不能檢查字符。 您可以檢查RichTextBox Inlines集合的Run元素。 但是您必須檢查它是否確實是Run或其他內容,例如完整的TextBlock或Image等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM