0

我在 DataGrid 中有很多按钮

我想根据我的 if 条件将 Button 的颜色设置为绿色,并将 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;

                }

一些身体请帮助我

4

3 回答 3

5

您正在引用ColoriTextSharp.text 命名空间中的类型。尝试明确指定命名空间:

btn.ForeColor = System.Drawing.Color.Red;
于 2012-08-24T15:22:24.207 回答
1

您可以使用 Button.BackColor 属性

例子 :

btn.BackColor = Color.Green;

更正: OP的问题标题具有误导性,以上内容基于此所以问题正文中解释的答案将与OP给出的相同

btn.ForeColor = Color.Red;//看不出这不起作用的原因

于 2012-08-24T15:20:36.750 回答
1

要更改背景颜色,请使用:

Button1.BackColor = Color.Red;

要更改前景色,请使用:

Button1.ForeColor = Color.Red;

您可以将它们都用于 MouseMove 事件。

要重置它们,请使用带有以下代码的 MouseLeave 事件:

Buttton1.BackColor = SystemColors.ButtonFace;
Button1.ForeColor = default(Color);
Button1.UseVisualStyleBackColor = true;
于 2018-02-18T19:31:04.760 回答