【发布时间】:2021-04-02 18:31:38
【问题描述】:
我想将所有面板的 BorderColor 更改为 Color.Lime:
foreach (Control G in GetAllControls (this))
{
Panel p = sender as Panel;
ControlPaint.DrawBorder(e.Graphics, p.DisplayRectangle, Color.Lime, ButtonBorderStyle.Inset);
}
它显示了这个错误:
严重性代码描述项目文件行抑制状态 错误 CS1061“EventArgs”不包含“Graphics”的定义,并且找不到接受“EventArgs”类型的第一个参数的可访问扩展方法“Graphics”(您是否缺少 using 指令或程序集引用?)
【问题讨论】:
-
这是按钮的点击事件吗? EventArgs 不会有 Graphics 对象。您必须改为在每个 Panel 的 Paint 事件中进行绘画。
-
哦,你能告诉我正确的吗?
-
我已经这样做了。
-
@LarsTech 还有其他方法吗?因为我有 100 多个面板,必须有更简单的方法来做到这一点。
标签: c# winforms graphics custom-controls gdi+