弹来弹去跑马灯!

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

  

posted @ 2019-03-25 14:16  wgscd  阅读(1937)  评论(2编辑  收藏  举报