c# WPF RichTextBox 文字颜色
public MainWindow() { InitializeComponent(); Run run = new Run("This is my text"); run.Foreground = new SolidColorBrush(Colors.Red); // My Color Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(run); run = new Run() { Text = "This itttttyyyyyyyyyy\r\nyyyyyyyyyyytttttts my text" , Foreground = new SolidColorBrush(Colors.Blue) }; paragraph.Inlines.Add(run); txtLog .Document.Blocks.Add(paragraph); txtLog.UpdateLayout();
//----------------写到一个公共方法更好-----------------------
display("PinkPinkPinkPinkPinkPink", Colors.Pink); } void display(string txt, Color color) { Run run = new Run() { Text = txt, Foreground = new SolidColorBrush(color) }; Paragraph paragraph = new Paragraph(); paragraph.Inlines.Add(run); txtLog.Document.Blocks.Add(paragraph); txtLog.UpdateLayout(); }
fffffffffffffffff
test red font.