C# 如何在c中更改按钮背面颜色#
我在DataGrid中有很多按钮 我想把它设置好 按钮的颜色变为绿色,按钮。文本根据我的if条件变为白色(并非全部,仅适用于1个按钮) 我一直使用ITextSharp创建PDF生成,我对ITextSharp头文件进行了注释,我得到了结果,但我必须在我的代码中使用ITextSharp,这一次出现了吼叫错误 “无法将类型iTextSharp.text.Color隐式转换为System.Drawing.Color” 这是我的iTextSharp头文件C# 如何在c中更改按钮背面颜色#,c#,background-color,C#,Background Color,我在DataGrid中有很多按钮 我想把它设置好 按钮的颜色变为绿色,按钮。文本根据我的if条件变为白色(并非全部,仅适用于1个按钮) 我一直使用ITextSharp创建PDF生成,我对ITextSharp头文件进行了注释,我得到了结果,但我必须在我的代码中使用ITextSharp,这一次出现了吼叫错误 “无法将类型iTextSharp.text.Color隐式转换为System.Drawing.Color” 这是我的iTextSharp头文件 using iTextSharp.text; us
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;
}
有人请帮我你可以使用Button.BackColor属性 例如:
btn.BackColor = Color.Green;
更正:OP的问题标题具有误导性,上述内容正是基于此
所以,问题主体的解释答案将与OP给出的答案相同
btn.ForeColor=Color.Red
//看不出这不起作用的原因您正在引用iTextSharp.text命名空间中的颜色
类型。尝试显式指定命名空间:
btn.ForeColor = System.Drawing.Color.Red;
要更改背景色,请使用:
Button1.BackColor = Color.Red;
Button1.ForeColor = Color.Red;
要更改前景色,请使用:
Button1.BackColor = Color.Red;
Button1.ForeColor = Color.Red;
您可以在MouseMove事件中同时使用这两个选项
要重置这两个选项,请使用带有以下代码的MouseLeave事件:
Buttton1.BackColor = SystemColors.ButtonFace;
Button1.ForeColor = default(Color);
Button1.UseVisualStyleBackColor = true;
你会得到,因为他们是不同的类型。如果数值相同,您可以选择铸造。他们希望更改前景色,但类型不同是问题所在。我理解-1我的答案基于OP问题标题,但OP的问题与他的标题完全不同misleading@HatSoft:我同意,+1,也许编辑你的答案,包括bothI没有-1你,但是你是对的,标题和细节与支持我的欢呼声不匹配guy’我使用了你的代码,但我得到了这个错误“对象引用未设置为对象的实例”。然后
btn
可能是null
。检查上面的FindControl
调用。是的,FindControl值为null,我使用一个单一网格视图FindControl值。在这种情况下,它是一个内部网格视图。我正在使用父GridView的RowDataBound事件绑定子GridView。我的问题是,如何在父gridViews RowDataBound事件中获取子GridView的Button findcontrol值@Steve Czetty如果有人知道,请帮我解决这个问题。提前谢谢。