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?
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.
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.
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.
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.
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;";
Try using the property ForeColor. Like this :
TextBox1.ForeColor = Color.Red;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With