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; using System.Collections; namespace polymesh { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private ArrayList pArray=new ArrayList(); private Pen pen1 = new Pen(Color.Red); bool isFinished = false; private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics(); int i; for( i=0;i<pArray.Count-1;i++) g.DrawLine(pen1, (Point)pArray[i], (Point)pArray[i+1]); if (pArray.Count >= 3 && isFinished) g.DrawLine(pen1, (Point)pArray[i], (Point)pArray[0]); } private void Form1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && !isFinished) { pArray.Add(new Point(e.X, e.Y)); this.Invalidate(); } if (e.Button == MouseButtons.Right) { isFinished = true; this.Invalidate(); } } } }
c# winform建立多边形
最新推荐文章于 2021-05-26 18:26:44 发布