If I want to upload a text file into the textbox and want to highlight certain words with a font color change, i know that i need to write TextBox.ForeColor = Color.SomeColor;
But if i want that not all the text will be in the same color, only some Substrings.
How can I do that?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Check the answer by Pieter Joost van de Sande.
As @syed-mohsin answered, it's possible to add text, then select portions of the text and change its color.
It's also possible to not select anything, set
SelectionColor
, and any appended text (eg throughAppendText
orText +=
) will have that color, until you changeSelectionColor
again. For example:richTextBox.AppendText("default color"); richTextBox.SelectionColor(Color.Green); richTextBox.AppendText("that will be in green"); richTextBox.SelectionColor(Color.Red); richTextBox.AppendText("that will be in red"); richTextBox.SelectionColor(Color.Black); richTextBox.AppendText("that will be in black");