c# WPF RichTextBox 文字颜色

2021-06-10 20:04

阅读:476

标签:log   round   add   new   --   text   spl   window   方法   

  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(); }

  

c# WPF RichTextBox 文字颜色

标签:log   round   add   new   --   text   spl   window   方法   

原文地址:https://www.cnblogs.com/wgscd/p/10593467.html


评论


亲,登录后才可以留言!