C # How to set text color in richtextbox?

I have a richtextbox in the application and I would like the keywords to be in a different color, how can I do this?

Thanks jade

+5
source share
2 answers

you can use:

richTextBox1.SelectionColor = Color.Yellow;
richTextBox1.SelectionBackColor = Color.Blue;

To select typing:

richTextBox1.SelectionStart = text_position_in_editor (caret position)

richTextBox1.SelectionLength = text_length

then set SelectionColor ... (all properties starting with Selection ...)

Or you can directly install Rtf property (or richTextBox1.SelectedRtf)that contains formatting information.

Enter the text in WordPad, change its formatting, copy and paste into your RichTextBox, show the value of the Rtf property, you can quickly find out how to satisfy your needs.

+11
source

, Rich Text Markup, . Rich Text

0

All Articles