Error: An object is required for the non-static field, method or property

i know im doing something really stupid but this is my first attempt to it anyway. what does it mean when it says call a method by instance or make it static?

namespace WindowsFormsApplication2
{
public partial class canvas : Form
{
public canvas()
{
InitializeComponent();
}

private void canvas_Paint(object sender, PaintEventArgs e)
{
Graphics gObject = canvas.CreateGraphics(); //this is where the error occurs

Brush red = new SolidBrush(Color.Red);

Pen redPen = new Pen(red, 8);

gObject.DrawLine(redPen, 10, 10, 400, 376);

}
}
}
1
2
3
4
private void canvas_Paint(object sender, PaintEventArgs e)
{
    Graphics gObject = canvas.CreateGraphics(); //this is where the error occurs
}


Funny is how you commented that line, because this is exactly the keyword missing here :)

1
2
3
4
private void canvas_Paint(object sender, PaintEventArgs e)
{
    Graphics gObject = this.CreateGraphics(); 
}
Last edited on
Topic archived. No new replies allowed.