// Create a new path object GraphicsPath path = new GraphicsPath(); // Add a line to the path path.AddLine(10, 10, 100, 100); // Draw the path on a Graphics object Graphics g = e.Graphics; g.DrawPath(Pens.Black, path);
// Create a new path object GraphicsPath path = new GraphicsPath(); // Add a rectangle to the path path.AddRectangle(new Rectangle(10, 10, 100, 100)); // Add an ellipse to the path path.AddEllipse(new Rectangle(50, 50, 50, 50)); // Draw the path on a Graphics object Graphics g = e.Graphics; g.FillPath(Brushes.Red, path);This code creates a path that consists of a rectangle and an ellipse, and then fills the path with a red brush. Overall, the System.Drawing namespace provides a powerful set of classes for creating and manipulating graphics in C#. The DrawPath class is just one of many classes available in this library.