【发布时间】:2018-06-25 18:32:47
【问题描述】:
嗨,我目前有一个 texbox,当用户按下不同的按钮时,它会向用户打印信息。我想知道是否有办法让我的部分文本只加粗,而其余部分不加粗。
我尝试了以下方法:
textBox1.FontWeight = FontWeights.UltraBold;
textBox1.Text. = ("Your Name: " );
TextBox1.FontWeight = FontWeights.Regular;
textBox1.Text += (nameVar);
唯一的问题是,使用这种方式要么使所有内容变得粗体,要么什么都没有。 有没有办法做到这一点?我在 C# 中使用 WPF 项目
任何意见或建议表示赞赏。 谢谢!
编辑:所以现在我正在尝试执行你们都建议的 RichText 框,但我似乎无法在其中显示任何内容:
// Create a simple FlowDocument to serve as the content input for the construtor.
FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("Simple FlowDocument")));
// After this constructor is called, the new RichTextBox rtb will contain flowDoc.
RichTextBox rtb = new RichTextBox(flowDoc);
rtb 是我在 wpf 中创建的富文本框的名称
谢谢
【问题讨论】:
-
嗯,我不知道这是否会对您有所帮助,但在 S.W.F(System.Windows.Forms) 命名空间中,有具有 SelectionFont 属性的 RichTextBox 类。我不知道它是否会不过可以使用 WPF。