1 void formsample_mousewheel(object sender, MouseEventArgs e) 2 { 3 //获取光标位置 4 Point mousepoint = new Point(e.X, e.Y); 5 //换算成相对本窗体的位置 6 mousepoint.Offset(this.Location.X, this.Location.Y); 7 //判断是否在panel内 8 if (pl_message.RectangleToScreen(pl_message.DisplayRectangle).Contains(mousepoint)) 9 { 10 //滚动 11 pl_message.AutoScrollPosition = new Point(0, pl_message.VerticalScroll.Value - e.Delta); 12 } 13 }
1 this.MouseWheel += formsample_mousewheel;