HorizontalScroll.Value won't programmatically set

前提是你 提交于 2019-12-12 16:04:52

问题


I have a Panel with scrollbars, and I frequently want to programmatically scroll a control into view. For reasons that don't bear mentioning I need my own methods. Frequently when I try to set

MyPanel.HorizontalScroll.Value = newScrollValue;

the value simply won't take. I can check MyPanel.HorizontalScroll.Value immediately after the set, and its value is unchanged. The values that I'm trying to set are definitely within the Minimum and Maximum range.

Now here's the worst part. I found out (don't ask how) that if I make the same set twice in a row, that fixes the problem most of the time. I really do have

MyPanel.HorizontalScroll.Value = newScrollValue;
MyPanel.HorizontalScroll.Value = newScrollValue;

and that really does mostly resolve the issue. But the issue persists when I'm programmatically scrolling to a control in an extremal corner of MyPanel. I tried setting the value three times and no dice.

Does anyone know what's going on or how to fix it? I mostly want to resolve the lingering issue.

~~~~~~

Edit: the lingering problem turned out to be a simple bug and I fixed it. The double-set fixes the problem in all cases. I would still like to know if anyone knows why the first set doesn't take, or if there's a more elegant way to fix the problem than the double-set.

来源:https://stackoverflow.com/questions/15559914/horizontalscroll-value-wont-programmatically-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!