日期:2014-05-17 浏览次数:20842 次
public Form1() { InitializeComponent(); } List<Rectangle> rects=new List<Rectangle>() ; private void Form1_MouseDown(object sender, MouseEventArgs e) { Graphics g = this.CreateGraphics(); Rectangle rect = new Rectangle(e.X,e.Y,100,100); g.DrawRectangle(Pens.Red, rect); rects.Add(rect); } private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (rects.Count() > 0) { Graphics g = this.CreateGraphics(); Rectangle rect = rects.Last(); int x = rect.X; int y = rect.Y; rect = new Rectangle(x, y, e.X - x, e.Y - y); g.DrawRectangle(Pens.Red, rect); //this.Refresh(); //rects.Add(rect); } } }