0
我想通过将它作为参数传递给另一个类中的函数来访问面板的图形对象,但我收到一个错误,说“参数无效”。
这是我使用的面板类代码:
从一个不同的类访问一个图形对象
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);
}
}
是否有可能访问Graphics对象来自不同班级的面板?