简体   繁体   English

如何以编程方式将标签的前景色设置为其默认值?

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

I'm using VS2010 C# ASP.NET我正在使用 VS2010 C# ASP.NET

To programmatically change the ForeColor of an asp:Label named lblExample to 'Red', I write this:要以编程方式将名为lblExample的 asp:Label 的 ForeColor 更改为“Red”,我这样写:

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)?更改前景色后,如何以编程方式将标签的前景色设置为其默认值(来自 css 文件)?

Remark: the label has no CSS entry (class or ID specific style).备注:标签没有 CSS 条目(类或 ID 特定样式)。 The color is inherited.颜色是继承的。

Easy 简单

if (lblExample.ForeColor != System.Drawing.Color.Red)
{
    lblExample.ForeColor = System.Drawing.Color.Red;
}
else
{
    lblExample.ForeColor = new System.Drawing.Color();
}

You can also use below format: 您还可以使用以下格式:

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

and

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

The default (when created with the designer) is: 默认(使用设计器创建时)是:

label.ForeColor = SystemColors.ControlText;

This should respect the system color settings (eg these "high contrast" schemes for visual impaired). 这应该尊重系统颜色设置(例如视觉障碍者的这些“高对比度”方案)。

你也可以使用

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

例如summer

lblSummer.foreColor = color.Yellow;
labelname.ForeColor = Color.Colorname;   ­­­­

DefaultForeColor is enough for this statement. DefaultForeColor足以用于此语句。 This property gets the default foreground color of the control. 此属性获取控件的默认前景色。

lblExample.ForeColor = DefaultForeColor;

ARBG = Color(alpha,Red,Blue,Green) you can set any value you want to but don't forget the Maximum value are 255 ARBG = Color(alpha,Red,Blue,Green) 你可以设置任何你想要的值,但不要忘记最大值是 255


Example :例子 :

labelname.ForeColor = Color.FromArbg(100,200,30);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM