6

My text is in a 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 change color font & text color of text :

1- For tags -> font name = Tahoma , size= 10,color=red

Example : <Parag1 Level="One"> Or </Parag1>

2- For Text between tags that tag's level is not Footer -> font name = Arial , size= 12,color=black

Example : First text of parag1. Second text of parag1. Or First text of parag4. Second text of parag4.

3- For Text between tags that tag's level is Footer -> font name = Microsoft Sans Serif, size= 8,color=blue

Example : First text of parag3. Second text of parag3.

How can I do it in c# ?(Changes font of all text at once!)

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Ali Ahmadi
  • 2,387
  • 4
  • 31
  • 48

1 Answers1

2

You would need to select parts of text and use SelectionColorand SelectionFontproperties. 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 test it so I don't know how it will act with the other colors you previously set.

Community
  • 1
  • 1
phadaphunk
  • 12,785
  • 15
  • 73
  • 107
  • Thank's PhaDaPhunk. How can I change font(fontname, size, style, color) of part of text that insert between text of richtextbox ? But font of other parts of text don't change. – Ali Ahmadi Apr 03 '12 at 22:59
  • I'm sorry I don't really understand what you're asking. Could you update your question and provide an example? – phadaphunk Apr 04 '12 at 01:29
  • Thank's from you. Please visit this link and replay it:[Link](http://stackoverflow.com/questions/10002827/insert-paragraph-between-text-of-richtextbox-and-change-font-and-color-of-added) – Ali Ahmadi Apr 04 '12 at 05:28
  • I'll try and find an answer to this question. – phadaphunk Apr 04 '12 at 14:52