未设置C#UserControl.VerticalScroll.Value [英] C# UserControl.VerticalScroll.Value not being set

查看:183
本文介绍了未设置C#UserControl.VerticalScroll.Value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆C#代码,它们应该在从UserControl继承的类中设置VerticalScroll.Value。当该类的任何子对象更改大小时,将调用该方法。该类的AutoScroll属性设置为true。

I've got a chunk of C# code that is supposed to set VerticalScroll.Value within a class that inherits from UserControl. It gets called when any child object of the class changes sizes. The class has its AutoScroll property set to true.

    public void ScrollTo(int top)
    {
        if (top >= this.VerticalScroll.Minimum && top <= this.VerticalScroll.Maximum)
        {
            this.VerticalScroll.Value = top;
        }
    }

问题是,在遍历代码时,有时设置了this.VerticalScroll.Value,有时它保留了调用此方法之前的值。

The problem is, when tracing through the code, sometimes this.VerticalScroll.Value gets set, sometimes it keeps the value that it had before this method was called.

这是VS中的错误,还是存在已知条件?

Is this a bug in VS, or are there known conditions under which the value will ignore attempts to set it?

谢谢,
Rob

Thanks, Rob

推荐答案

我遇到了同样的问题,并在某个开发人员论坛上提出了解决方案。设置VerticalScroll.Value后,必须调用PerformLayout()来使滚动控件更新。这样做:

I was having the same problem and came upon the solution in some dev forum. After setting the VerticalScroll.Value, you have to call PerformLayout() to make the scrolling control update. So do this:

scrollingcontrol.VerticalScroll.Value = top;
scrollingcontrol.PerformLayout();

这比两次设置.Value更有意义,尽管它似乎具有相同的效果。

This makes more sense than setting .Value twice, though it seems to have the same effect.

这篇关于未设置C#UserControl.VerticalScroll.Value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆