[英]How to Change button back color in c#
我在DataGrid中有很多按钮
我想将Button的颜色设置为Green,将Button.Text设置为白色(不是全部用于1个按钮),前提是我已经使用ITextSharp创建PDF生成了,我评论了iTextSharp头文件结果,但这次必须出现以下错误,因此我必须在代码中使用iTextSharp。
“无法将类型iTextSharp.text.Color隐式转换为System.Drawing.Color”
这是我的iTextSharp头文件
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
这是代码
if (dsRecAdj.Tables[2].Rows.Count > 0)
{
Button btn = (Button)e.Row.FindControl("btnSalvage");
btn.ForeColor = Color.Red;
}
有些身体请帮助我
您正在iTextSharp.text命名空间中引用Color
类型。 尝试显式指定名称空间:
btn.ForeColor = System.Drawing.Color.Red;
您可以使用Button.BackColor属性
范例:
btn.BackColor = Color.Green;
更正: OP的问题标题具有误导性,并且以上内容基于此,因此问题正文中的解释答案将与OP给出的答案相同
btn.ForeColor = Color.Red;
//看不到为什么它不起作用的原因
要更改BackColor,请使用:
Button1.BackColor = Color.Red;
要更改ForeColor,请使用:
Button1.ForeColor = Color.Red;
您可以将它们都用于MouseMove事件。
若要重置它们两者,请使用带有以下代码的MouseLeave事件:
Buttton1.BackColor = SystemColors.ButtonFace;
Button1.ForeColor = default(Color);
Button1.UseVisualStyleBackColor = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.