المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Passing a Graphics object



C# Programming
06-21-2009, 01:11 AM
I want to make a game draw its Board so I have been trying to pass the graphics object. I get an error saying that the

NullReferenceException
"Object reference not set to an instance of an object."

I use

In the form's Paint function

Graphics g = this.CreateGraphics();
game.DrawBoard(g);

game is a variable in the form and DrawBoard is a function of that class

public void DrawBoard(Graphics g)
{
....
}
I have also tried passing the PaintEventArgs e with the same result

It works if I make the function belong to the form but that is not what I want to do

I vaguely remember from C++ that I might need to use handles but I have not been able to find a solution.

Can anybody help?



Alan