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