Scrollbar does not update on changing the scroll value

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

    I ran into something nearly identical where I have a PictureBox (showing a graph) inside a panel with scroll bars, and I want to zoom in or out keeping the mouse-pointer position "apparently" stationary. Re-positioning the PictureBox inside the panel to do this throws off synchronization with the scroll bars, and thereafter, scrolling with the scroll bars will not show the full area of the PictureBox. The solution is to accomplish the move by assigning a computed value to the panel.HorizontalScroll.Value and/or panel.VerticalScroll.Value properties. But that alone isn't enough: one of these two solutions is required to make the application behave as designed:

    1. KMan's solution above:

      panel.HorizontalScroll.Value = computed_value
      panel.PerformLayout()
      
    2. Or JJMcLellan's solution above: in my case, assigning the computed value twice, e.g.:

      panel.HorizontalScroll.Value = computed_value
      panel.HorizontalScroll.Value = computed_value
      

    Either one of these appears to have the same end results. Since #2 above makes it look like a bug, and #1 seems (hopefully) to be by design by Microsoft (?), I ended up using #1 in my application. I just wanted to confirm both these work in a VB.NET environment.

提交回复
热议问题