日期:2014-05-18 浏览次数:22840 次
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
}
private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
MessageBox.Show(e.Delta.ToString());
//this.pictureBox1.Width = 50;
}
//给窗口添加句柄。
this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
void Form1_MouseWheel(object sender, MouseEventArgs e)
{
var t = pictureBox1.Size;
t.Width += e.Delta;
t.Height += e.Delta;
pictureBox1.Size = t;
}
------解决方案--------------------
主要是Picture控件得不到焦点,所以滚动没有效果
在它的MouseEnter事件里面设置它的焦点
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
pictureBox1.Focus();
}
void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
double scale = 1;
if (pictureBox1.Height > 0)
{
scale = (double)pictureBox1.Width / (double)pictureBox1.Height;
}
pictureBox1.Width += (int)(e.Delta * scale);
pictureBox1.Height += e.Delta;
}
------解决方案--------------------
xuexi
------解决方案--------------------
刚才试了一下还有一个方便点的。
1:设置Image属性;
2:调整Sizemode为Zoom;
在事件响应中不需要同时调整高和宽了,只需要调整一个即可。(你根据需要自己确定,这种缩放会自动保持比例)。
这个方案要好得多。
需要的话发消息给我我可以发我的测试代码给你。
------解决方案--------------------
自己重写PictureBox的Paint过程就行了
Image用Graphics画上去,如果缩放,完全自己控制
在PictureBox的MouseWheel事件中,计算出图像的尺寸,然后让PictureBox Invalidate
------解决方案--------------------
晓习来了
------解决方案--------------------
結合3樓5樓的答案應該比較完美
------解决方案--------------------
有个按钮事件
里面可以找到滚轮键值
捕捉键值进行处理就可以了
------解决方案--------------------
如果没有解决的话,可以看看我的代码
[DllImport("user32.dll")]
public static extern int WindowFromPoint(int xPoint, int yPoint);
void Form1_MouseWheel(object sender, MouseEventArgs e)
{
System.Drawing.Point p= PointToScreen(e.Location);
if (WindowFromPoint(p.X, p.Y) == pictureBox1.Handle.ToInt32())
{
if (e.Delta == 120)
{
MessageBox.Show("向前");
}
else if(e.Delta<0)
{
MessageBox.Show("向后");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
}