栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在WPF C#中更改文本某些部分的颜色和字体

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在WPF C#中更改文本某些部分的颜色和字体

如果您只想进行快速着色,则将RTB内容的末尾作为范围并对其应用格式可能是最简单的解决方案,例如

  TextRange rangeOfText1 = new TextRange(richTextBox.document.ContentEnd, richTextBox.document.ContentEnd);  rangeOfText1.Text = "Text1 ";  rangeOfText1.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);  rangeOfText1.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);  TextRange rangeOfWord = new TextRange(richTextBox.document.ContentEnd, richTextBox.document.ContentEnd);  rangeOfWord.Text = "word ";  rangeOfWord.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);  rangeOfWord.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Regular);  TextRange rangeOfText2 = new TextRange(richTextBox.document.ContentEnd, richTextBox.document.ContentEnd);  rangeOfText2.Text = "Text2 ";  rangeOfText2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue);  rangeOfText2.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

如果您正在寻找更高级的解决方案,建议阅读有关Flowdocument的MSDN页面,因为这为您设置文本格式提供了极大的灵活性。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470651.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号