读书人

如何实现单击鼠标图片变小双击鼠标图片

发布时间: 2012-12-27 10:17:09 作者: rapoo

怎么实现单击鼠标图片变小双击鼠标图片变大啊~~~~


所以小妹又来求大神相助啦~下面附上我的零零乱乱的代码。。。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;


}




并不是所有屏蔽掉的语句都不要了。。。哎呀TAT我只是在做实验。。。相信大神懂的。。。。

谢大神。。TAT
[解决办法]
引用:
引用:
我不是大神,所以不懂!
坐上沙发~


帮顶~~~

忽忽~~~~谢谢帮顶的盆友~~~~~


帮你刷刷~~~~ 我觉得嘛 你的标题应该改成小妹有个问题想请问各位大牛,或者大哥什么的,保证你的贴子一个小时内,能建到100楼~ 这群丝怎么还没出场呢?
[解决办法]
鼠标移动事件是看得网上的 不过效果不是很好 建议用windows API来做


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);
}
}


------解决方案--------------------


引用:
引用:


我想问呢。。。。有没有一个东西。。。可以直接用来控制双击。。。。比如说我举个例子哈。。。。

if (e.Button == MouseDoubleClick)

像这样的可以写在条件句啊类似句子里的。。。。。(当然标红的这个是错的。。我瞎编的)

很有悟性嘛、
MouseDoubleClick你可以想成是一个变量、
当你触发双击事件的时候就把一个值赋给它、
然后if (e.Button == 你赋给的值(MouseDoubleClick))

[解决办法]
改为用滚轮缩放吧!

先要注重用户体验的交互设计,然后才是编程。
[解决办法]
引用:
引用:引用:引用:触摸板有模拟鼠标滚轮操作的

唔唔唔。。能不能帮忙解决一下按右键移动时。。。图片也会变小的问题。。。
嗯 我去看看

讷讷~~~~谢谢谢谢~~~~

把pictureBox1_Click和pictureBox1_DoubleClick这两个事件去掉 换成下面这两个

/// <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;
}
}

读书人网 >C#

热点推荐