如何使用c#更改后面代码中的标签字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19578858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change label font in code behind using c#
提问by niru dyogi
I fetched the date into the text fields from db. Now in case of failure, I want to show a label ( inside a panel) font color to red.
我从 db 中将日期提取到文本字段中。现在如果失败,我想将标签(面板内)字体颜色显示为红色。
I tried like this :
我试过这样:
if (success)
{
Panel_Message.Visible = false;
}
else
{
Panel_Message.Visible = true;
Label_Fail.Visible = true;
Label_Fail.Text = "Invalid Last Name and Employee Number";
}
采纳答案by deathismyfriend
This should help
这应该有帮助
label1_Fail.ForeColor = Color.Red;
Thanks for the edit lol. Stupid mistake
谢谢你的编辑哈哈。愚蠢的错误
回答by Matthew Verstraete
You would either need to create a CSS Class with the styling you want and then use the CssClass
property, like this:
您要么需要使用您想要的样式创建一个 CSS 类,然后使用该CssClass
属性,如下所示:
Label.CssClass = "Class";
or if you want in-line styling, then do this:
或者,如果您想要内联样式,请执行以下操作:
Label.Attributes.Add("style", "font: FONT;");
回答by Helmer
Like this:
像这样:
LabelFail.ForeColor = System.Drawing.Color.Red;