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

5

15

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?

Pollie answered 3/4, 2012 at 9:42 Comment(0)
D
32
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;";
Downpipe answered 3/4, 2012 at 9:44 Comment(0)
L
3

Try using the property ForeColor. Like this :

TextBox1.ForeColor = Color.Red;
Laurenelaurens answered 3/4, 2012 at 9:45 Comment(0)
A
1
string minusvalue = TextBox1.Text.ToString();

if (Convert.ToDouble(minusvalue) < 0)
{ 
    // set color of text in TextBox1 to red color and bold.
    TextBox1.ForeColor = Color.Red;
}
Aney answered 3/4, 2012 at 9:55 Comment(0)
S
0

Another way of doing it. This approach can be useful for changing the text to 2 different colors, just by adding 2 spans.

Label1.Text = "String with original color" + "<b><span style=""color:red;"">" + "Your String Here" + "</span></b>";
Schmaltzy answered 15/5, 2020 at 2:51 Comment(0)
U
0

try this one:

label { color: red; font-weight:bold;}
label span { color: blue; font-weight:bold;}
<label>Label With Color <span>And Bold Text</span> </label>
Unfetter answered 11/8, 2021 at 4:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.