本文介绍了AutoScrollPosition 设置到点位置后不报正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,它是可滚动控件,我想更改它的 AutoScrollPosition(仅 X 值).

I have a user control, which is scrollable control, and I want to change its AutoScrollPosition (only the X value).

我是这样做的:

int newScrollX = myFunction();
Point p = new Point(newScrollX, this.AutoScrollPosition.Y);
this.AutoScrollPosition = p;

newScrollX 得到正确的值,p 得到正确的点,但是在 AutoScrollPosition 设置的那一行之后,AutoScrollPosition 是 (0,0).

newScrollX gets the correct value, p gets the correct point, but after the line of AutoScrollPosition setting, the AutoScrollPosition is (0,0).

有什么问题?

谢谢

推荐答案

AutoScrollPosition 相当麻烦.

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)

否则,观察到的 AutoScrollPosition 将为 0,0.

Otherwise the AutoScrollPosition will be 0,0 as observed.

这篇关于AutoScrollPosition 设置到点位置后不报正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 04:07