我尝试使用鼠标滚轮启用缩放功能,但是当我启动项目时缩放功能不起作用
我的代码
Form1.Designer.cs
this.Panel4.AutoScroll = true;
this.Panel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.Panel4.Controls.Add(this.pictureBox4);
this.Panel4.Controls.Add(this.pictureBox3);
this.Panel4.Location = new System.Drawing.Point(175, 353);
this.Panel4.Name = "Panel4";
this.Panel4.Size = new System.Drawing.Size(1163, 365);
this.Panel4.TabIndex = 7;
Form1.cs
添加MouseWheel事件
InitializeComponent();
Panel4.MouseWheel += new MouseEventHandler(Panel4_MouseWheel);
当我滚动鼠标滚轮时,此功能处于活动状态
private void Panel4_MouseWheel(object sender, MouseEventArgs e)
{
Console.WriteLine("Zoom!!");
this.Focus();
// or Panel4.Focus();
if (e.Delta < 120 && zoomIn_zoomOut > 1)
{
zoomIn_zoomOut--;
zoom_len -= zoomIn_zoomOut;
}
else if (e.Delta >= 120)
{
zoomIn_zoomOut++;
zoom_len += zoomIn_zoomOut;
}
factor = new Size(zoomIn_zoomOut, 1);
zoom_pic(factor, e);
}
void zoom_pic(Size scale, MouseEventArgs e)
{
// Calculate and zoom Picture
}
期望结果
Zoom!!
实际结果
(show nothing)
您能告诉我这段代码是什么问题吗?我没有办法解决。
非常感谢您