C# Winform 画圆 代码收藏

纯属代码收藏

 

public partial class Form3 : Form { public Form3() { InitializeComponent(); this.DoubleBuffered = true; } private Point startPoint; private bool beginDragging; private void Form3_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { startPoint = e.Location; beginDragging = true; this.Capture = true; circle = new Circle(); circle.Location = e.Location; Circles.Add(circle); this.Cursor = System.Windows.Forms.Cursors.Cross; } } private void Form3_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && beginDragging) { circle.Size = new Size(circle.Size.Width + e.X - startPoint.X, circle.Size.Height + e.Y - startPoint.Y); startPoint = new Point(e.X, e.Y); } this.Invalidate(); } private void Form3_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && beginDragging) { beginDragging = false; this.Capture = false; this.Cursor = System.Windows.Forms.Cursors.Default; } this.Invalidate(); } private void Form3_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; foreach (Circle each in Circles) { g.DrawEllipse(Pens.Black, new Rectangle(each.Location, each.Size)); } } private List<Circle> Circles = new List<Circle>(); private Circle circle = new Circle(); } public class Circle { public int Radii { get; set; } public Size Size { get; set; } public Point Location { get; set; } }

你可能感兴趣的:(object,C#,Class,each,WinForm)