日期:2014-05-18 浏览次数:21103 次
//定义鼠标事件 private void pictureBox1_MouseDown_1(object sender, MouseEventArgs e) { this.Cursor = Cursors.Cross; this.p1 = new Point(e.X, e.Y); } private void pictureBox1_MouseUp_1(object sender, MouseEventArgs e) { this.Cursor = Cursors.Default; this.p2 = new Point(e.X, e.Y); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (this.Cursor == Cursors.Cross) { this.p2 = new Point(e.X, e.Y); this.pictureBox1.Invalidate(); } } //定义鼠标事件 private void pictureBox1_Paint_1(object sender, PaintEventArgs e)//在图片框画图 { Pen p = new Pen(Color.Black, 1);//画笔 p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; Rectangle rect = new Rectangle(p1, new Size(p2.X - p1.X, p2.Y - p1.Y)); e.Graphics.DrawRectangle(p, rect); }