c#在pictureBox上剪切图片问题
剪切图片功能实现了,剪切方法是用鼠标点击,向下拖动形成一个矩形框。但有些小问题。
1.如何实现鼠标向上拖动功能禁用,即向上拖动后什么也不做(目前向上拖动后,会导致程序错误)
2.如何设置鼠标拖动后矩形框的颜色。(我现在设置的,但矩形框没有颜色,透明的)
鼠标代码如下:
//定义鼠标事件 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); }