Hello Mat

 找回密码
 立即注册
查看: 3098|回复: 0

实现鼠标滚轮的操作

[复制链接]

84

主题

115

帖子

731

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
1467
发表于 2021-4-11 17:15:20 | 显示全部楼层 |阅读模式
实现鼠标滚轮的操作
  1.             //鼠标滚动
  2.             this.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
复制代码
添加事件:
  1.         private void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
  2.         {
  3.             if (e.Delta < 0)
  4.             {
  5.                 ZoomIn();
  6.             }
  7.             else
  8.             {
  9.                 ZoomOut();
  10.             }
  11.         }
  12.         private void ZoomIn()
  13.         {
  14.             if (pictureBox1.Width < panel_Picture.Width * 20 || pictureBox1.Height < panel_Picture.Height * 20)
  15.             {
  16.                 float factor = 1.1f;
  17.                 pictureBox1.Width = (int)(pictureBox1.Width * factor);
  18.                 pictureBox1.Height = (int)(pictureBox1.Height * factor);
  19.             }
  20.             else
  21.             {
  22.                 return;
  23.             }
  24.         }
  25.         private void ZoomOut()
  26.         {
  27.             float factor = 0.9f;
  28.             if (pictureBox1.Width * factor <= 0.1 * panel_Picture.Width || pictureBox1.Height * factor <= 0.1 * panel_Picture.Height)
  29.             {
  30.                 return;
  31.             }
  32.             else
  33.             {
  34.                 pictureBox1.Width = (int)(pictureBox1.Width * factor);
  35.                 pictureBox1.Height = (int)(pictureBox1.Height * factor);
  36.             }
  37.         }
复制代码



参考:
【1】C# 使用鼠标滚动实现图片的放大缩小及图片拖动
【2】c#-使用鼠标滚轮缩放图像.




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-27 07:10 , Processed in 0.212208 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表