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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容