about some drawing

T

Tony Johansson

Hello!

Below I have a method Form1_Paint that does some drawing on the screen.
Now to my question what is the point to have a method AddRectangle in class
GraphicsPath when
class Graphics have the method DrawRectangle. In my example rows marked
with 1 and 2 in the code draw
identically rectangle. So why have methods in classes that is not necessary
because in this case we already have
DrawRectangle in class Graphics.

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Red, 7);
GraphicsPath graphPath = new GraphicsPath();
Point myPoint = new Point(1, 1);
Size mySize = new Size(100, 200);

1 graphPath.AddRectangle(new Rectangle(myPoint, mySize));
1 g.DrawPath(p, graphPath);

2 g.DrawRectangle(p, new Rectangle(myPoint, mySize));
}

//Tony
 
A

Alberto Poblacion

Tony Johansson said:
Now to my question what is the point to have a method AddRectangle in
class
GraphicsPath when
class Graphics have the method DrawRectangle.

GraphicsPath is not necessarily used for drawing. For example, you can
use a GraphicsPath for creating a form with a non-standard shape. In such a
case, it would make sense that the shape of the form contains a rectangle,
which would be achieved by means of AddRectangle, but the DrawRectangle
would not be useful since we would not be drawing anything.

Conversely, you may draw on a form without ever using a GraphicsPath,
which is where DrawRectangle is useful.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top