WPF RichTextBox附加彩色文本 [英] WPF RichTextBox appending coloured text

查看:541
本文介绍了WPF RichTextBox附加彩色文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 RichTextBox.AppendText 函数向我的 RichTextBox 添加一个字符串。我想设置一个特定的颜色。


b

$ p> TextRange tr = new TextRange(rtb.Document.ContentEnd,rtb.Document.ContentEnd);
tr.Text =textToColorize;
tr.ApplyPropertyValue(TextElement.ForegroundProperty,Brushes.Red);


I'm using the RichTextBox.AppendText function to add a string to my RichTextBox. I'd like to set this with a particular colour. How can I do this?

解决方案

Just try this:

TextRange tr = new TextRange(rtb.Document.ContentEnd,­ rtb.Document.ContentEnd);
tr.Text = "textToColorize";
tr.ApplyPropertyValue(TextElement.­ForegroundProperty, Brushes.Red);

这篇关于WPF RichTextBox附加彩色文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆