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建立多边形
最新推荐文章于 2025-05-22 09:51:02 发布
本示例展示如何使用 C# 在 Windows Forms 应用程序中绘制一个多边形。通过鼠标左键添加顶点,并使用右键完成多边形的绘制。程序使用 ArrayList 存储顶点坐标,并在 Form 的 Paint 事件中进行绘制。

763

被折叠的 条评论
为什么被折叠?



