Scrollbar does not update on changing the scroll value

后端 未结 5 1017
失恋的感觉
失恋的感觉 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:10

    Thanks for the .PerformLayout() tip!

    It wasn't enough in my case, I am setting the VerticalScroll.Value within the form Form.Shown event handler, and for some reason I had to add a DoEvents instruction beforehand for the scrolling to work.

    Here's my Shown event handler:

    Private Sub MyForm_Shown(sender As System.Object, e As System.EventArgs) Handles Me.Shown
        System.Windows.Forms.Application.DoEvents()
    
        ScrollPanel.VerticalScroll.Value = ScrollPanel.VerticalScroll.Maximum
        ScrollPanel.PerformLayout()
    End Sub
    

    ScrollPanel control is of type System.Windows.Forms.Panel.

    Without the Application.DoEvents() line, the vertical scrolling value setting was completely ignored.

    I thought it might came in handy for someone else.

提交回复
热议问题