码迷,mamicode.com
首页 > Windows程序 > 详细

c# WPF RichTextBox 文字颜色

时间:2019-03-25 14:40:04      阅读:444      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!