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);//滚动
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询