Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set color of text in a Textbox/Label to Red and make it bold

I want a text color to be red in color on certain condition.

Here is how i want to get it done.

string minusvalue = TextBox1.Text.ToString();
if (Convert.ToDouble(minusvalue) < 0)
{ 
// set color of text in TextBox1 to red color and bold.
}

Is there any function that can set the property of text in TextBox?

like image 503
Ishan Avatar asked Apr 03 '12 09:04

Ishan


People also ask

How do I change the color of my text to red?

Select the text that you want to change. On the Home tab, in the Font group, choose the arrow next to Font Color, and then select a color.

How do I change the color of text in a label in Java?

You can set the color of a JLabel by altering the foreground category: JLabel title = new JLabel("I love stackoverflow!", JLabel. CENTER); title. setForeground(Color.

How do I change the color of text in a label in HTML?

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. HTML5 do not support the <font> tag, so the CSS style is used to add font color.

Which tag is used to change the text color to red?

To change some of the text in the HTML document to another color use the FONT COLOR Tag. To change the color of the font to red add the following attribute to the code to the <FONT COLOR=" "> tag. #ff0000 is the color code for red.


2 Answers

TextBox1.ForeColor = Color.Red;
TextBox1.Font.Bold = True;

Or this can be done using a CssClass (recommended):

.highlight
{
  color:red;
  font-weight:bold;
}

TextBox1.CssClass = "highlight";

Or the styles can be added inline:

TextBox1.Attributes["style"] = "color:red; font-weight:bold;";
like image 88
Curtis Avatar answered Oct 02 '22 10:10

Curtis


Try using the property ForeColor. Like this :

TextBox1.ForeColor = Color.Red;
like image 38
Kristof Avatar answered Oct 02 '22 11:10

Kristof