theUser
theUser

Reputation: 1396

How to Scroll a Panel through code?

I have a Panel that I wish to scroll horizontally through code, the problem is that it only seems to scroll every second time the line of code is executed. This is what Im using

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

This is what happens every time,

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

.... ... Repeat

Upvotes: 1

Views: 2271

Answers (1)

LarsTech
LarsTech

Reputation: 81675

Try using the AutoScrollPosition instead (and you need to inverse the value):

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

Upvotes: 4

Related Questions