.NET触发MouseWheel事件

来源:互联网 发布:图册排版设计软件 编辑:程序博客网 时间:2024/04/28 19:09

 

该方法适用于ListBox,Panel等,可惜ListView小弟我没有try成功。

        private int fontSize = 6;

        
private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.MouseWheel 
+= new MouseEventHandler(this.listBox1_MouseWheel);
            listBox1.SelectedIndex 
= 10;

        }

        
private void listBox1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            
int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
            
int numberOfPixelsToMove = numberOfTextLinesToMove * fontSize;
            GraphicsPath mousePath 
= new GraphicsPath();
            
if (numberOfPixelsToMove != 0)
            {
                System.Drawing.Drawing2D.Matrix translateMatrix 
= new System.Drawing.Drawing2D.Matrix();
                translateMatrix.Translate(
0, numberOfPixelsToMove);
                mousePath.Transform(translateMatrix);
            }
            listBox1.Invalidate();

        }
 
原创粉丝点击