[英]Change the color of a line in Richtextbox
我要第二行,更改為另一種顏色。
我的代碼如下:
private void WindowLoaded(object sender, RoutedEventArgs e)
{
UpdateRTBOnDifferentThread("stackoverflow.com" + Environment.NewLine+"stackoverflow.org" + Environment.NewLine);
}
private void UpdateRTBOnDifferentThread(string message)
{
Dispatcher.Invoke(DispatcherPriority.Normal, new DispatcherOperationCallback(delegate
{
var newExternalParagraph = new Paragraph(new Run(message)) {Foreground = Brushes.Black};
richTextBox1.Document.Blocks.Add(newExternalParagraph);
return null;
}), null);
}
第二行是:“ stackoverflow.org”
我要在輸入文字后更改顏色
您可以使用String.Split
來中斷UpdateRTBOnDifferentThread
方法中的行,也可以使此方法接受字符串數組。 然后,您可以迭代該數組並在同一段落內添加N個Paragraph對象或N個Run對象,並分別控制每個字符串的前景。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.