怎么实现单击鼠标图片变小双击鼠标图片变大啊~~~~ 本帖最后由 heyheyyoyo 于 2012-12-16 19:28:55 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+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); } } TAT。我在看你给的代码~~~好长好长。。呜呜呜简直是要疯了 我比较笨嘛。。又刚学TAT。好困可以明天再写么。 我想问呢。有没有一个东西可以直接用来控制双击。比如说我举个例子哈。if (e.Button == MouseDoubleClick)像这样的可以写在条件句啊类似句子里的。。(当然标红的这个是错的。。我瞎编的) 很有悟性嘛、MouseDoubleClick你可以想成是一个变量、当你触发双击事件的时候就把一个值赋给它、然后if (e.Button == 你赋给的值(MouseDoubleClick)) 嗷嗷嗷怎么解释。。就是像 if (e.Button == MouseButtons.Left) 里的MouseButtons.Left是一个事件直接控制击左键,有没有一个事件可以直接控制双击的。。而不用再 private void pictureBox1_DoubleClick(object sender, EventArgs e) 这样写。。 嘿嘿嘿不要夸我我笨得要死~~~ >w<..唔可是e.Buttou是可以随便赋值的?如果不是系统内自己包含的事件。我自己赋的值怎么让e.Button响应。? 在click事件里判断一下是不是鼠标左键点击的 可是如果用if (e.Button == MouseButtons.Left)。。来判断它会报错因为头上那个是private void pictureBox1_DoubleClick(object sender, EventArgs e)不是MouseEventArgs e。了可是除了那样判断其他的我就不会了 确实是呢。TAT没想到。可是用本本的话木有滚轮。。 把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; } } 讷~!我竟然忘记了还有mouseclick这个东西!!!!!!!!!太谢谢您啦!!!!!!!!!!!!~~~~~~~不过我觉得36#的大哥说得对~~忽忽~~不过我想做的终于是实现了~~!!!!谢谢大家!!!!! 真正高手帮忙,求c#实现的Delauny三角剖分算法,最好是分治算法实现 比较两个dataset? 继承类和支持接口问题 关于继承窗体的问题?(onLoad) windows2000 server 有没有自带的群发信息的软件?如果有在哪里能找到? 局部刷新 c#输入的小问题 在win2000、98下如何得到硬盘物理的序列号!(非逻辑序列号)~(比较难) C#如何实现链表操作啊? C#中什么控件可以实现此类下拉框? 基础好的进!我想给子类的父类中的static变量赋值 用c#语言编写值班表
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);
}
}
TAT。我在看你给的代码~~~好长好长。。呜呜呜简直是要疯了
我想问呢。有没有一个东西可以直接用来控制双击。比如说我举个例子哈。if (e.Button == MouseDoubleClick)像这样的可以写在条件句啊类似句子里的。。(当然标红的这个是错的。。我瞎编的)
MouseDoubleClick你可以想成是一个变量、
当你触发双击事件的时候就把一个值赋给它、
然后if (e.Button == 你赋给的值(MouseDoubleClick))
就是像 if (e.Button == MouseButtons.Left) 里的MouseButtons.Left是一个事件直接控制击左键,
有没有一个事件可以直接控制双击的。。而不用再 private void pictureBox1_DoubleClick(object sender, EventArgs e) 这样写。。
嘿嘿嘿不要夸我我笨得要死~~~ >w<..
唔可是e.Buttou是可以随便赋值的?如果不是系统内自己包含的事件。我自己赋的值怎么让e.Button响应。?
可是如果用if (e.Button == MouseButtons.Left)。。来判断它会报错因为头上那个是private void pictureBox1_DoubleClick(object sender, EventArgs e)不是MouseEventArgs e。了可是除了那样判断其他的我就不会了
确实是呢。TAT没想到。可是用本本的话木有滚轮。。
/// 鼠标单击事件
/// </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;
}
}
讷~!我竟然忘记了还有mouseclick这个东西!!!!!!!!!太谢谢您啦!!!!!!!!!!!!~~~~~~~不过我觉得36#的大哥说得对~~忽忽~~不过我想做的终于是实现了~~!!!!谢谢大家!!!!!