public DrawPath ( |
||
pen | ||
path | ||
return | void |
using System.Drawing; using System.Windows.Forms; public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen blackPen = new Pen(Color.Black, 3); // Create a path and add lines and curves GraphicsPath path = new GraphicsPath(); path.AddLine(30, 30, 60, 120); path.AddEllipse(70, 70, 100, 60); path.AddBezier(150, 30, 180, 60, 210, 0, 240, 30); // Draw the path using the black pen g.DrawPath(blackPen, path); } }
using System.Drawing; using System.Windows.Forms; public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Pen redPen = new Pen(Color.Red, 3); Pen greenPen = new Pen(Color.Green, 3); // Create two paths GraphicsPath path1 = new GraphicsPath(); path1.AddEllipse(30, 30, 100, 60); GraphicsPath path2 = new GraphicsPath(); path2.AddBezier(150, 30, 180, 60, 210, 0, 240, 30); // Draw the paths using different pens g.DrawPath(redPen, path1); g.DrawPath(greenPen, path2); } }This example demonstrates how to create two GraphicsPath objects with different shapes and draw them on a form using different pens. Package Library: System.Drawing
public DrawPath ( |
||
pen | ||
path | ||
return | void |