剪切图片功能实现了,剪切方法是用鼠标点击,向下拖动形成一个矩形框。但有些小问题。
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);
}
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);
}
至于颜色,你的知道什么是向上,向下,自己根据方向设置brush的颜色啊
在print里面先判断一下计算过的坐标是否符合逻辑,不符合就不做修改
至于你说的颜色问题,这个需要在MouseMove里面写draw,边拖边画一个带颜色的矩形。