实现鼠标滚轮的操作
实现鼠标滚轮的操作//鼠标滚动
this.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);添加事件:
private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta < 0)
{
ZoomIn();
}
else
{
ZoomOut();
}
}
private void ZoomIn()
{
if (pictureBox1.Width < panel_Picture.Width * 20 || pictureBox1.Height < panel_Picture.Height * 20)
{
float factor = 1.1f;
pictureBox1.Width = (int)(pictureBox1.Width * factor);
pictureBox1.Height = (int)(pictureBox1.Height * factor);
}
else
{
return;
}
}
private void ZoomOut()
{
float factor = 0.9f;
if (pictureBox1.Width * factor <= 0.1 * panel_Picture.Width || pictureBox1.Height * factor <= 0.1 * panel_Picture.Height)
{
return;
}
else
{
pictureBox1.Width = (int)(pictureBox1.Width * factor);
pictureBox1.Height = (int)(pictureBox1.Height * factor);
}
}
参考:
【1】C# 使用鼠标滚动实现图片的放大缩小及图片拖动
【2】c#-使用鼠标滚轮缩放图像.
页:
[1]