I have a System.Windows.Forms.Panel
with some content.
I am trying to programmatically scroll the panel (vertically) either up or down.
I have t
If you have a class that derives from Panel
, then call these two protected methods to scroll the panel:
// The bottom is off screen; scroll down. These coordinates must be negative or zero.
SetDisplayRectLocation(0, AutoScrollPosition.Y - item.BoundingRect.Bottom + ClientRectangle.Bottom);
AdjustFormScrollbars(true);
In my example, item.BoundingRect.Bottom
is the Y coordinate of the bottom of a thumbnail, and I need to scroll the panel down so that the whole thumbnail is visible.
@King King's solution of creating a temporary Control just so that scrolling could be done seemed "heavy" to me. And @Hans Passant's suggestion of setting AutoScrollMinSize
and AutoScrollPosition
didn't work for me.
Leave AutoScroll
to its default value of 'true'.