• 大小: 130KB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: 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 DrawPolygon
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Setstyle(Controlstyles.UserPaint true);
            Setstyle(Controlstyles.AllPaintingInWmPaint true); // 禁止擦除背景.  
            Setstyle(Controlstyles.DoubleBuffer true); // 双缓冲
        }

        List ListPolyon = new List();
        List _tempPolyon = new List();
        Point _tempPoint = new Point();
        bool IsDrawPolyonstart = false;

        bool IsEdit = false;
        int SelectListIndex = 0;
        int SelectRc = 0;
        public float isLeft1(Point P0 Point P1 Point P2)
        {
            float abc = ((P1.X - P0.X) * (P2.Y - P0.Y) - (P2.X - P0.X) * (P1.Y - P0.Y));
            return abc;

        }
        private bool PointInFences(Point pnt1 Point[] fencePnts)
        {

            int wn = 0 j = 0; //wn 计数器 j第二个点指针
            for (int i = 0; i < fencePnts.Length; i++)
            {//开始循环
                if (i == fencePnts.Length - 1)
                    j = 0;//如果 循环到最后一点 第二个指针指向第一点
                else
                    j = j + 1; //如果不是 ,则找下一点


                if (fencePnts[i].Y <= pnt1.Y) // 如果多边形的点 小于等于 选定点的 Y 坐标
                {
                    if (fencePnts[j].Y > pnt1.Y) // 如果多边形的下一点 大于于 选定点的 Y 坐标
                    {
                        if (isLeft1(fencePnts[i] fencePnts[j] pnt1) > 0)
                        {
                            wn++;
                        }
                    }
                }
                else
                {
                    if (fencePnts[j].Y <= pnt1.Y)
                    {
                        if (isLeft1(fencePnts[i] fencePnts[j] pnt1) < 0)
                        {
                            wn--;
                        }
                    }
                }
            }
            if (wn == 0)
                return false;
            else
                return true;
        }
        private void pictureBox1_MouseDoubleClick(object sender MouseEventArgs e)
        {
            if (!IsDrawPolyonstart)
            {
                if (_tempPolyon.Count <= 2)
                {
                    MessageBox.Show(“多边形至少三个点“);
                    return;
                }
                IsDrawPolyonstart = true;
                _tempPolyon.Add(new Point(e.X e.Y));

                _tempPolyon.Add(_tempPolyon[0]);


                ListPolyon.Add(_tempPolyon.ToArray());





                _tempPolyon = new List();
            }
            if (IsDrawPolyonstart && e.Button == MouseButtons.Right)
            {

                for (int i =

评论

共有 条评论