鼠标滚轮控制panel滚动条

来源:互联网 发布:广东开放大学网络教学 编辑:程序博客网 时间:2024/03/29 14:53
在Form类中添加FormSample_MouseWheel方法


   


View Code 


 /// <summary>
        /// 滚动方法
        /// </summary>
         /// <param name="sender"></param>
        /// <param name="e"></param>
        void FormSample_MouseWheel(object sender, MouseEventArgs e)
         {
             //获取光标位置
             Point mousePoint = new Point(e.X, e.Y);
            //换算成相对本窗体的位置
            mousePoint.Offset(this.Location.X, this.Location.Y);
            //判断是否在panel内
           if (panel_content.RectangleToScreen(panel_content.DisplayRectangle).Contains(mousePoint))
           {
               //滚动
                panel_content.AutoScrollPosition = new Point(0, panel_content.VerticalScroll.Value - e.Delta);
            }
0 0
原创粉丝点击