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對象來自不同班級的面板?