Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 358
George Tyler Avatar asked May 11 '10 18:05

George Tyler


People also ask

What is the syntax to change Font color?

To set the font color in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property color.

How do we set the foreground color of the TextBox control?

Following steps are used to set the ForeColor property of the TextBox: Step 1 : Create a textbox using the TextBox() constructor provided by the TextBox class. // Creating textbox TextBox Mytextbox = new TextBox(); Step 2 : After creating TextBox, set the ForeColor property of the TextBox provided by the TextBox class.


2 Answers

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.

like image 200
Will Marcouiller Avatar answered Sep 19 '22 19:09

Will Marcouiller


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.

like image 35
Brandi Avatar answered Sep 19 '22 19:09

Brandi