【问题标题】:How to bold a RichTextBox through button click?如何通过按钮单击加粗 RichTextBox?
【发布时间】:2016-10-12 16:15:10
【问题描述】:

我目前用来加粗文本的代码是这样的:

rtb.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

但这样做的缺点是必须先突出显示文本,然后才能应用粗体。

有没有一种方法可以使 RichTextBox 中的下一个输入文本变为粗体,而无需突出显示和选择文本?

【问题讨论】:

  • 你检查过答案吗

标签: wpf formatting richtextbox bold


【解决方案1】:
if(rtb.CaretPosition.Parent is TextElement)
{
  (rtb.CaretPosition.Parent as TextElement).FontWeight = FontWeights.Bold;
}

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    相关资源
    最近更新 更多