C#中如何设置滚动条跟随鼠标移动呢
panel1.AutoScrollPosition=newPoint(e.X,e.Y);无法达到目的...
panel1.AutoScrollPosition = new Point(e.X, e.Y);无法达到目的
展开
2个回答
展开全部
先在formload里加载mousewheel事件:
this.MouseWheel+=new MouseEventHandler(Panel_MouseWheel);
然后代码里加入函数:
private void RightPanel_MouseWheel(object sender, MouseEventArgs e)
{
Point mousePoint = new Point(e.X, e.Y);
mousePoint.Offset(this.Location.X, this.Location.Y);
if (Panel.RectangleToScreen(Panel.DisplayRectangle).Contains(mousePoint))
{
Panel.AutoScrollPosition = new Point(0,Panel.VerticalScroll.Value - e.Delta);//滚动
}
}
this.MouseWheel+=new MouseEventHandler(Panel_MouseWheel);
然后代码里加入函数:
private void RightPanel_MouseWheel(object sender, MouseEventArgs e)
{
Point mousePoint = new Point(e.X, e.Y);
mousePoint.Offset(this.Location.X, this.Location.Y);
if (Panel.RectangleToScreen(Panel.DisplayRectangle).Contains(mousePoint))
{
Panel.AutoScrollPosition = new Point(0,Panel.VerticalScroll.Value - e.Delta);//滚动
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询