在richtextbox中更改文本字体

我的文本位于richtextbox中:

 First text of parag1. Second text of parag1.   First text of parag2. Second text of parag2.   First text of parag3. Second text of parag3.   First text of parag4. Second text of parag4.  

我想要更改文本的颜色字体和文本颜色:

1-对于标签 – > font name = Tahoma,size = 10,color = red

示例:

2-对于标签之间的文本,标签的级别不是页脚 – >字体名称= Arial,大小= 12,颜色=黑色

示例: First text of parag1. Second text of parag1. First text of parag1. Second text of parag1. 或者First text of parag4. Second text of parag4. First text of parag4. Second text of parag4.

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

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

如何在c#中执行此操作?(一次更改所有文本的字体!)

您需要选择部分文本并使用SelectionColorSelectionFont属性。 这里解释了一切。

希望这可以帮助

现在,对于您的其他问题,如果您的意思是如何更改程序运行时插入的文本的字体和颜色,请尝试此操作。

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

我没有时间测试它,所以我不知道它将如何与您之前设置的其他颜色一起使用。