【问题标题】:Change font of text in richtextbox更改richtextbox中文本的字体
【发布时间】:2012-04-02 20:58:13
【问题描述】:

我的文本在一个富文本框中:

<Parag1 Level="One">
First text of parag1. Second text of parag1.
</Parag1>
<Parag2 Level="Two">
First text of parag2. Second text of parag2.
</Parag2>
<Parag3 Level="Footer">
First text of parag3. Second text of parag3.
</Parag3>
<Parag4 Level="Three">
First text of parag4. Second text of parag4.
</Parag4>

我想改变文字的颜色字体和文字颜色:

1- 对于标签 -> 字体名称 = Tahoma , size= 10,color=red

例如:&lt;Parag1 Level="One"&gt;&lt;/Parag1&gt;

2- 对于标签级别不是 Footer 的标签之间的文本 -> 字体名称 = Arial , size= 12,color=black

例如:First text of parag1. Second text of parag1.First text of parag4. Second text of parag4.

3- 对于标签级别为 Footer 的标签之间的文本 -> 字体名称 = Microsoft Sans Serif, size= 8,color=blue

例如:First text of parag3. Second text of parag3.

如何在 c# 中做到这一点?(一次更改所有文本的字体!)

【问题讨论】:

  • 请不要在您的标题中添加“C#”。这就是标签的用途。

标签: c# richtextbox


【解决方案1】:

您需要选择部分文本并使用SelectionColorSelectionFontproperties。 一切都解释了here

希望对你有帮助

现在对于您的另一个问题,如果您的意思是如何更改在程序运行时插入的文本的字体和颜色,请试试这个。

         private void someTextBox_KeyPress(object sender, KeyPressEventArgs e)
         {
           this.someTextBox.SelectionColor = Color.Blue; 
           // Same goes for font and other properties
         }

我没有时间测试它,所以我不知道它与你之前设置的其他颜色的效果如何。

【讨论】:

  • 感谢 PhaDaPhunk。如何更改插入 Richtextbox 文本之间的部分文本的字体(字体名称、大小、样式、颜色)?但是文本其他部分的字体不会改变。
  • 对不起,我不太明白你在问什么。您能否更新您的问题并提供一个示例?
  • 感谢您。请访问此链接并重播:Link
  • 我会试着找到这个问题的答案。
猜你喜欢
  • 2011-07-28
  • 2012-07-28
  • 2016-10-24
  • 2013-10-25
  • 1970-01-01
  • 2013-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多