日期:2014-05-18 浏览次数:20624 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace HaveATry { public partial class Form1 : Form { ArrayList points; Point currentPoint; Pen thepen; float penwidth; SolidBrush thebrush; Color thecolor; public Form1() { InitializeComponent(); } private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Point[] ps=(Point[])points.ToArray(typeof(Point)); if (radioButton1.Checked) g.DrawLine(Pens.Black, ps[0], ps[ps.Length - 1]); else if (radioButton2.Checked) g.DrawRectangle(thepen, ps[0].X, ps[0].Y, ps[ps.Length - 1].X - ps[0].X, ps[ps.Length - 1].Y - ps[0].Y); } private void Form1_MouseUp(object sender, MouseEventArgs e) { if (currentPoint.X != e.X || currentPoint.Y != e.Y) { currentPoint.X = e.X; currentPoint.Y = e.Y; points.Add(currentPoint); this.Invalidate(); this.Update(); } } } }