Scrollbar does not update on changing the scroll value

后端 未结 5 1011
失恋的感觉
失恋的感觉 2020-12-10 15:16

When setting VerticalScroll.Value in a Panel with AutoScroll set to true, the scroll position changes accordingly but the

5条回答
  •  被撕碎了的回忆
    2020-12-10 16:03

    I was trying to get it to work on a Form. I tried the PerformLayout(), I tried Application.DoEvents(), I tried assigning the VerticalScroll.Value twice, none of it worked. The only thing I got to work was to change a property of VerticalScroll to a different value, and then change it back:

    protected override void OnVisibleChanged(EventArg e)
    {
        base.OnVisibleChanged(e);
        if (this.Visible)
        {
            this.VerticalScroll.Maximum++;
            this.VerticalScroll.Maximum--;
        }
    }
    

    Note that it works just as well to change VerticalScroll.Value, but you have to actually modify its value, and making sure the change is in the range of Minimum to Maximum is a lot more complex than just increasing Maximum temporarily.

提交回复
热议问题