How to change the font color in the textbox in C#?

2019-03-22 16:51发布

If I want to upload a text file into the textbox and want to highlight certain words with a font color change, how can I do that without drawing the text?

Thank you.

2条回答
Juvenile、少年°
2楼-- · 2019-03-22 17:42

Assuming WinForms, the ForeColor property allows to change all the text in the TextBox (not just what you're about to add):

TextBox.ForeColor = Color.Red;

To only change the color of certain words, look at RichTextBox.

查看更多
孤傲高冷的网名
3楼-- · 2019-03-22 17:50

RichTextBox will allow you to use html to specify the color. Another alternative is using a listbox and using the DrawItem event to draw how you would like. AFAIK, textbox itself can't be used in the way you're hoping.

查看更多
登录 后发表回答