怎么实现单击鼠标图片变小双击鼠标图片变大啊~~~~
所以小妹又来求大神相助啦~下面附上我的零零乱乱的代码。。。TAT
private void pictureBox1_MouseMove(object sender,System.Windows.Forms.MouseEventArgs e)
{
this.Text=String.Concat("当前鼠标位置:","(",e.X.ToString(),",",e.Y.ToString(),")");
/* if (e.Button == MouseButtons.Left)
{
pictureBox1.Location = new Point(Cursor.Position.X - (p.X - cp.X), Cursor.Position.Y - (p.Y - cp.Y));
}*/
}
private void pictureBox1_MouseHover(object sender, System.EventArgs e)
{
this.Text = "单击左键放大图片,单击右键缩小图片,用光标移动图片";
}
private void pictureBox1_MouseLeave(object sender, System.EventArgs e)
{
this.Text = "作品信息查询";
}
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
/* p.X = Cursor.Position.X;
p.Y = Cursor.Position.Y;
cp.X = pictureBox1.Location.X;
cp.Y = pictureBox1.Location.Y;*/
//double scale = 1.0;
if (e.Button == MouseButtons.Left) scale = 0.9;
//if (e.Button == MouseDoubleClick) scale = 0.9;
pictureBox1.Size = new System.Drawing.Size((int)(pictureBox1.Width * scale), (int)(pictureBox1.Height * scale));
}
double scale = 1.0;
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
scale = 1.1;
}
public partial class Form7 : Form
{
int with, height;
Point downPoint;
Rectangle downRectangle;
Rectangle lastRectangle;
public Form7()
{
InitializeComponent();
}
private void Form7_Load(object sender, EventArgs e)
{
//获取图片框的宽高
this.with = this.pictureBox1.Width;
this.height = this.pictureBox1.Height;
}
/// <summary>
/// 单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_Click(object sender, EventArgs e)
{
//如果当前图片框的宽高大于初始的宽高 说明已放大 则还原初始大小
if(this.pictureBox1.Width > this.with && this.pictureBox1.Height > this.height)
{
this.pictureBox1.Width = this.with;
this.pictureBox1.Height = this.height;
}
}
/// <summary>
/// 双击放大 宽高各增加50像素
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
this.pictureBox1.Width += 50;
this.pictureBox1.Height += 50;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != System.Windows.Forms.MouseButtons.Right)
return;
downPoint = e.Location;
downRectangle = new Rectangle(0, 0, this.pictureBox1.Width, this.pictureBox1.Height);
downRectangle.Offset(this.pictureBox1.PointToScreen(new Point(0, 0)));
ControlPaint.DrawReversibleFrame(downRectangle, Color.White, FrameStyle.Thick);
lastRectangle = downRectangle;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != System.Windows.Forms.MouseButtons.Right)
return;
ControlPaint.DrawReversibleFrame(lastRectangle, Color.White, FrameStyle.Thick);
Rectangle rectangle = downRectangle;
rectangle.Offset(e.X - downPoint.X, e.Y - downPoint.Y);
ControlPaint.DrawReversibleFrame(rectangle, Color.White, FrameStyle.Thick);
lastRectangle = rectangle;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != System.Windows.Forms.MouseButtons.Right)
return;
ControlPaint.DrawReversibleFrame(lastRectangle, Color.White, FrameStyle.Thick);
pictureBox1.Location = new Point(((Control)sender).Location.X + e.X - downPoint.X,((Control)sender).Location.Y + e.Y - downPoint.Y);
}
}
/// <summary>
/// 鼠标单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
//判断是否是按的鼠标左键 避免按到右键误操作
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
//如果当前图片框的宽高大于初始的宽高 说明已放大 则还原初始大小
if (this.pictureBox1.Width > this.with && this.pictureBox1.Height > this.height)
{
this.pictureBox1.Width = this.with;
this.pictureBox1.Height = this.height;
}
}
}
/// <summary>
/// 鼠标双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
//判断是否是按的鼠标左键
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
this.pictureBox1.Width += 50;
this.pictureBox1.Height += 50;
}
}