C# 添加鼠标滚轮事件

首先定义窗体鼠标滚轮事件

 private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
              Graphics g=this.CreateGraphics();  // GDI+绘图
              g.Clear(BackColor);         //  用背景色刷新绘图区域
              Pen pen=new Pen(Color.Blue,2);   //  定义画笔
              if (e.Delta != 0)
              {
                  if (_controlKey)
                  {
                     if (e.Delta > 0)
                         ScaleAtCenterS(g, pen, points, 1.2f, 1.2f);
                     else
                         ScaleAtCenterS(g, pen, points, 0.8f, 0.8f);
                 }
                 else
                 {
 
  
                }
             }
       }

最后在窗体初始化过程中,添加滚轮事件

 public Form1()
 {
            InitializeComponent();
            MouseWheel += new MouseEventHandler(Form1_MouseWheel);
 }

转载地址:https://www.cnblogs.com/braceli/p/5358677.html

猜你喜欢

转载自blog.csdn.net/wojiuguowei/article/details/121007317