Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar does not update on changing the scroll value

When setting VerticalScroll.Value in a Panel with AutoScroll set to true, the scroll position changes accordingly but the position of the thumb does not. Do I need to update the scrollbar somehow (Invalidate(true) on the panel does not work)? Any ideas?

like image 313
EricSchaefer Avatar asked Apr 06 '11 11:04

EricSchaefer


2 Answers

Try calling .PerformLayout();

like image 74
KMån Avatar answered Oct 10 '22 04:10

KMån


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.

like image 6
Julien P Avatar answered Oct 10 '22 04:10

Julien P