[c#] How to programmatically set the ForeColor of a label to its default?

I'm using VS2010 C# ASP.NET

To programmatically change the ForeColor of an asp:Label named lblExample to 'Red', I write this:

lblExample.ForeColor = System.Drawing.Color.Red;

After changing the ForeColor, how do I programmatically set the ForeColor of the label to its default (that comes from the css file)?

Remark: the label has no CSS entry (class or ID specific style). The color is inherited.

This question is related to c# asp.net

The answer is


DefaultForeColor is enough for this statement. This property gets the default foreground color of the control.

lblExample.ForeColor = DefaultForeColor;

labelname.ForeColor = Color.Colorname;   ­­­­

You can also use below format:

Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#22FF99");

and

HyperLink1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#22FF99");

For example summer :

lblSummer.foreColor = color.Yellow;

The default (when created with the designer) is:

label.ForeColor = SystemColors.ControlText;

This should respect the system color settings (e.g. these "high contrast" schemes for visual impaired).


You can also use

lblExamlple.ForeColor = System.Drawing.Color.FromArgb(0,255,0);