标签的backcolor属性在代码端不起作用 [英] backcolor property of label not work from codeside

查看:206
本文介绍了标签的backcolor属性在代码端不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有灰色背景,我尝试了不同的方法,但是没有用.

I want to have Gray background, i tried with diffrent ways but did''nt work.

using System.Drawing;
////
lbdetail.BackColor = System.Drawing.Color.Red;



如何使用System.Drawing使用自定义颜色代码,例如"#eee".



How can I Use Custom color code like " #eee ".

推荐答案



颜色colorName = System.Drawing.ColorTranslator.FromHtml(#eeee");
lbdetail.BackColor = colorName;

这段代码对我来说很好用..尝试一下..别忘了给出适当的十六进制颜色:)

快乐的编码....
using System.Drawing;

Color colorName = System.Drawing.ColorTranslator.FromHtml("#eeee");
lbdetail.BackColor = colorName;

this code is working fine for me..try it..don forget to give proper hexadecimal colors :)

happy coding....


包含名称空间
使用System.Drawing;

以及每当您要更改颜色时写
label1.backcolor = color.red;

如果要在加载表单时更改颜色,则可以在
中编写代码 公共表格1()
{
InitializeComponent();
label1.backcolor = color.red;
}

表单加载事件.
Include a namespace
using System.Drawing;

and whenever you want to change the color write
label1.backcolor=color.red;

if want to change the color when the form loads then you can write the code in
public form1()
{
InitializeComponent();
label1.backcolor=color.red;
}
or
forms load event..


JawadHafiz写道:
我在Webform上使用,但尝试了但没用


试试这个-
JawadHafiz wrote:
i am using on webform, I tried but did''nt work


Try this -
lbdetail.ForeColor = System.Drawing.Color.Red;


这篇关于标签的backcolor属性在代码端不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆