来源:http://www.cnblogs.com/kiny/articles/2508116.html
1.画矩形
DrawRectangle(Pen pen, Rectangle rect) DrawRectangle(Pen pen, float x, float y, float width, float height) DrawRectangle(Pen pen, int x, int y, int width, int height) DrawRectangles(Pen pen, Rectangle[] rects) DrawRectangles(Pen pen, RectangleF[] rects)
private void Form1_Paint(object sender, PaintEventArgs e) { //创建画板从Paint事件中的直接引用Graphics对象 Graphics graphics = e.Graphics; graphics.Clear(Color.Black); //定义画笔 Pen pen = new Pen(Color.White, 3.0f); //矩形区域 Rectangle[] rect = { new Rectangle(50, 50, 300, 100), new Rectangle(50,50,300,300), new Rectangle(100,100,200,400) }; graphics.DrawRectangles(pen, rect); }
2.画多边形
DrawPolygon(Pen pen, Point[] points)
DrawPolygon(Pen pen, PointF[] points)
private void Form1_Paint(object sender, PaintEventArgs e) { //创建画板从Paint事件中的直接引用Graphics对象 Graphics graphics = e.Graphics; graphics.Clear(Color.Black); //定义画笔 Pen pen = new Pen(Color.White, 3.0f); //多边形个点坐标 Point[] points = { new Point(10,10), new Point(5,25), new Point(35,200), new Point(80,100), new Point(50,70) }; graphics.DrawPolygon(pen, points); }