Skip to main content
 首页 » 编程设计

c#之如何通过代码滚动面板

2024年02月20日12lhb25

我有一个面板,我希望通过代码水平滚动, 问题是它似乎只在执行代码行时每隔一秒滚动一次。 这就是我正在使用的

 private void MyScrollButton_Click(object sender, EventArgs e) 
 { 
    MainPanel.HorizontalScroll.Value += 64; 
 } 

每次都是这样

1st Click: Panel Scrolls and ScrollBar Remains Still 
2nd Click: Panel remains still and ScrollBar scrolls 
3rd Click: Same as 1st 
4th Click: Same as 2nd 

.... ... 重复

请您参考如下方法:

尝试使用 AutoScrollPosition 代替(并且您需要反转值):

private void MyScrollButton_Click(object sender, EventArgs e) { 
  MainPanel.AutoScrollPosition = new Point(-MainPanel.AutoScrollPosition.X + 64, 
                                           -MainPanel.AutoScrollPosition.Y); 
}