我正在使用wpf和visual basic。当我在RichTextBox中选择文本时,我使用TextRange:
dim selection1 as New TextRange(Richtextbox.selection.start,Richtextbox.selection.end)
随后:
selection1.ApplyPropertyValue(ForegroundProperty, brushes.Red)
当我多次标记文本时,颜色也会在之前的选择中发生变化。我想改变颜色只有最后选择。怎么做?
答案 0 :(得分:0)
为什么不缓存之前的选择和以前的颜色?
RichTextBox.BeginChange();
selection?.ApplyPropertyValue(ForegroundProperty, lastColor);
selection = RichTextBox.Selection;
selection.ApplyPropretyValue(ForegroundProperty, newColor);
RichTextBox.EndChange();