如何通过代码滚动面板?

时间:2012-05-15 15:32:14

标签: c# winforms visual-studio-2008

我有一个Panel,希望在代码中水平滚动, 问题是它似乎只是每隔一次滚动执行代码行。 这就是我使用的

 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

.... ... 重复

1 个答案:

答案 0 :(得分:4)

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

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