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);
        }

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM