c#画多边形

代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp16
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //创建Graphics对象
            Graphics GPS = this.CreateGraphics();
            //创建笔,确定多边形颜色为黑色,宽度为3
            Pen blackPen = new Pen(Color.Black, 3);
            //定义多边形顶点
            Point pt1 = new Point(90, 30);
            Point pt2 = new Point(50, 60);
            Point pt3 = new Point(90, 90);
            Point pt4 = new Point(170, 90);
            Point pt5 = new Point(210, 60);
            Point pt6 = new Point(170, 30);
            //定义point结构数组,用来表示多边形的点
            Point[] curvePoints = { pt1, pt2, pt3, pt4, pt5, pt6 };
            //绘制多边形
            GPS.DrawPolygon(blackPen, curvePoints);
        }
    }
}

运行结果

AfterRun.PNG

你可能感兴趣的:(c#画多边形)