【发布时间】:2011-09-06 15:10:44
【问题描述】:
我试图通过将 Panel 的 Graphics 对象作为参数传递给不同类中的函数来访问它,但我收到一条错误消息,提示“参数无效”。
这是我在面板类中使用的代码:
Graphics g = contentPan.CreateGraphics();//contentPan is a Panel
RectMaker rect_Maker = new RectMaker();
rect_Maker.Draw(g);
这是驻留在 RectMaker 类中的函数:
public void Draw(Graphics g)
{
try
{
g.FillRectangles(Brushes.White, SmallRect);
g.DrawRectangles(Pens.Black, SmallRect);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
是否可以从不同的类访问 Panel 的 Graphics 对象?
【问题讨论】:
标签: c# winforms graphics panel