I have a user control, which is scrollable control, and I want to change its AutoScrollPosition
(only the X value).
I'm doing it like this:
int newScrollX = myFunction();
Point p = new Point(newScrollX, this.AutoScrollPosition.Y);
this.AutoScrollPosition = p;
newScrollX gets the correct value, p gets the correct point, but after the line of AutoScrollPosition setting, the AutoScrollPosition is (0,0).
What is the problem?
Thanks
AutoScrollPosition is quite cumbersome.
usually you get negative values when doing this:
Point p = this.AutoScrollPosition;
but when setting the scroll position you have to use positive values... so to restore the exact same scroll position you have to invert the negative numbers:
this.AutoScrollPosition = new Point(-p.X, -p.Y)
Otherwise the AutoScrollPosition will be 0,0 as observed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With