在RichtextBox中着色文本,C#
如何使用不同的颜色为新文本行着色,然后将其添加到RichTextBox? 我正在使用SilverLight。
您可以在代码中执行此操作:
//创建一个包含两个彩色运行的段落 Paragraph para = new Paragraph(); 运行run1 = new Run(“Red”); run1.Foreground = Brushes.Red; 运行run2 = new Run(“Green”); run2.Foreground = Brushes.Green; para.Inlines.Add(RUN1); para.Inlines.Add(RUN2); //获取文档 FlowDocument doc = richTextBox1.Document; //清除现有内容 doc.Blocks.Clear(); //添加新内容 doc.Blocks.Add(对位);
或者在XAML中:
Red Green