【问题标题】:How to use multi color in richtextbox WPF如何在richtextbox WPF中使用多色
【发布时间】:2016-01-24 18:18:23
【问题描述】:

我使用 C# WPF 并且我有richtextbox,我想将一些文本着色为红色、一些绿色和一些黑色。 该怎么做?

【问题讨论】:

标签: wpf


【解决方案1】:

在您的 RichTextBox 中使用 FlowDocumentReader。因此,您可以使用文档类:List、Paragraph、Section、Table、LineBreak、Figure、Floater 和 Span,并更改它们的属性:

<FlowDocumentReader x:Name="myDocumentReader" Height="269.4">
<FlowDocument>
<Section Foreground = "Yellow" Background = "Black">
<Paragraph FontSize = "20">
Here are some fun facts about the WPF Documents API!
</Paragraph>
</Section>
<List x:Name="listOfFunFacts"/>
<Paragraph x:Name="paraBodyText"/>
</FlowDocument>
</FlowDocumentReader>

您还可以在代码中填充和更改属性,例如,List right:

this.listOfFunFacts.Foreground = Brushes.Brown;
this.listOfFunFacts.FontSize = 14;
this.listOfFunFacts.MarkerStyle = TextMarkerStyle.Circle;
this.listOfFunFacts.ListItems.Add(new ListItem( new Paragraph(new Run("Sample Text"))));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-24
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 2011-07-20
    • 2011-07-27
    • 1970-01-01
    相关资源
    最近更新 更多