Change text font in richtextbox
My text is in 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>
I want to change the font color and text color of the text:
1- For tags -> font name = Tahoma, size = 10, color = red
Example: <Parag1 Level="One">
Or </Parag1>
2- For text between tags, the tag level is not lower β font name = Arial, size = 12, color = black
Example: First text of parag1. Second text of parag1.
First text of parag1. Second text of parag1.
Or First text of parag4. Second text of parag4.
First text of parag4. Second text of parag4.
3- For text between tags, tag level - Footer β Font Name = Microsoft Sans Serif, size = 8, color = blue
Example: First text of parag3. Second text of parag3.
First text of parag3. Second text of parag3.
How can I do this in C #? (Changes the font of all text at once!)
You will need to select parts of the text and use the SelectionColor
and SelectionFont
properties. Everything is explained here .
Hope this helps
Now for your other question, if you mean how to change the font and color of the text inserted while the program is running, try this.
private void someTextBox_KeyPress(object sender, KeyPressEventArgs e) { this.someTextBox.SelectionColor = Color.Blue; // Same goes for font and other properties }
I donβt have time to check it, so I donβt know how it will work with other colors that you previously set.