我的文字位于richtextbox中:
<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>
Run Code Online (Sandbox Code Playgroud)
我想要更改文本的颜色字体和文本颜色:
1-对于标签 - >字体名称= Tahoma,尺寸= 10,颜色=红色
示例:<Parag1 Level="One">或</Parag1>
2-对于标签之间的文本,标签的级别不是页脚 - >字体名称= Arial,大小= 12,颜色=黑色
示例:First text of parag1. Second text of parag1.或First text of parag4. Second text of parag4.
3-对于标签之间的文本标签的级别是页脚 - >字体名称= Microsoft Sans Serif,size = 8,color = blue
示例: First text of parag3. Second text of parag3.
如何在c#中执行此操作?(一次更改所有文本的字体!)
您需要选择部分文本以及用途SelectionColor和SelectionFont属性。一切都在这里解释了。
希望这可以帮助
现在,对于您的另一个问题,如果您的意思是如何更改程序运行时插入的文本的字体和颜色,请尝试这个。
private void someTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
this.someTextBox.SelectionColor = Color.Blue;
// Same goes for font and other properties
}
Run Code Online (Sandbox Code Playgroud)
我没有时间测试它,所以我不知道它与您之前设置的其他颜色的效果如何。