Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically set the ForeColor of a label to its default?

Tags:

c#

asp.net

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.

like image 274
Different111222 Avatar asked May 04 '12 00:05

Different111222


People also ask

What is ForeColor in C#?

The ForeColor property is an ambient property. An ambient property is a control property that, if not set, is retrieved from the parent control. For example, a Button will have the same BackColor as its parent Form by default.


2 Answers

Easy

if (lblExample.ForeColor != System.Drawing.Color.Red) {     lblExample.ForeColor = System.Drawing.Color.Red; } else {     lblExample.ForeColor = new System.Drawing.Color(); } 
like image 106
Gabriel Graves Avatar answered Sep 18 '22 04:09

Gabriel Graves


You can also use below format:

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

and

HyperLink1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#22FF99"); 
like image 31
raha Avatar answered Sep 19 '22 04:09

raha