C# 添加鼠标滚轮事件

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

1
private void Form1_MouseWheel(object sender, MouseEventArgs e) 2 { 3 Graphics g=this.CreateGraphics(); // GDI+绘图 4 g.Clear(BackColor);         // 用背景色刷新绘图区域 5 Pen pen=new Pen(Color.Blue,2);   // 定义画笔 6 if (e.Delta != 0) 7 { 8 if (_controlKey) 9 { 10 if (e.Delta > 0) 11 ScaleAtCenterS(g, pen, points, 1.2f, 1.2f); 12 else 13 ScaleAtCenterS(g, pen, points, 0.8f, 0.8f); 14 } 15 else 16 { 17 18 19 } 20 } 21 }


最后在窗体初始化过程中,添加滚轮事件
 public Form1()
        {
            InitializeComponent();
            MouseWheel += new MouseEventHandler(Form1_MouseWheel);
        }

写的较为简单,仍需完善。

原文地址:https://www.cnblogs.com/braceli/p/5358677.html