// Create a new GraphicsPath object GraphicsPath path = new GraphicsPath(); // Add a line to the path path.AddLine(0, 0, 100, 100); // Draw the path on a graphics object Graphics graphics = Graphics.FromImage(myImage); graphics.DrawPath(Pens.Black, path);
// Create a new GraphicsPath object GraphicsPath path = new GraphicsPath(); // Add a rectangle to the path path.AddRectangle(new Rectangle(10, 10, 80, 80)); // Add an ellipse to the path path.AddEllipse(new Rectangle(30, 30, 40, 40)); // Draw the path on a graphics object Graphics graphics = Graphics.FromImage(myImage); graphics.DrawPath(Pens.Black, path);This code creates a GraphicsPath object, adds a rectangle to it, and then adds an ellipse inside the rectangle. The resulting image will show a shape that resembles a donut. The System.Drawing.Drawing2D namespace is a part of the System.Drawing assembly, which is included in the .NET Framework.