方法如下:
在窗體的Load事件注冊滾動事件,並增加對應的方法
代碼如下:
private void FormSample_Load(object sender, EventArgs e)
{
//注冊事件
this.MouseWheel += new MouseEventHandler(FormSample_MouseWheel);
}
/// <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 (pnlDownload.RectangleToScreen(
pnlDownload.DisplayRectangle).Contains(mousePoint))
{
//滾動
pnlDownload.AutoScrollPosition = new Point(
, pnlDownload.VerticalScroll.Value - e.Delta);
}
}