Hi guys I'm trying to make a "minipaint" application which has three buttons(rectangle, circle and line). I'm having problem with making my buttons work. For example I have this rectangle class which inherits color, thickness, startpoints x, y from shape:
class rectangle : shape
{
public int length { get; set; }
public int width { get; set; }
public override void Draw(Graphics g)
{
g.DrawRectangle(new Pen(color), new Rectangle(startx, starty, width, length));
}
}
Now I want my rectangle_btn_Click to print a rectangle in my panel whenever I click on it. here is my panel code:
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = panel1.CreateGraphics();
}
and this is my button:
private void rectangle_btn_Click(object sender, EventArgs e)
{
rectangle r = new rectangle();
int retval = r.Draw(g);
}
But it has an error and it does not recognize g. How should I make this work?