From: Tony Johansson on 14 Jun 2010 03:57 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
From: Alberto Poblacion on 14 Jun 2010 05:09 "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message news:OdC89c5CLHA.5476(a)TK2MSFTNGP06.phx.gbl... > 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.
From: Peter Duniho on 14 Jun 2010 11:12 Alberto Poblacion wrote: > "Tony Johansson" <johansson.andersson(a)telia.com> wrote in message > news:OdC89c5CLHA.5476(a)TK2MSFTNGP06.phx.gbl... >> 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. [...] And even when it is, it would generally be used to cache drawing commands for repeated use later, rather than being created from scratch each time you need to draw the control. There's not really any point in creating a new GraphicsPath from scratch each time the Paint event handler is called, if all you're doing with the GraphicsPath is drawing it. But that doesn't mean that the GraphicsPath class isn't useful. It just means it's useful for other things. Pete
|
Pages: 1 Prev: using error messages Next: Asynchronous Socket programing and Thread Pool |