Search code examples
c#.netwinformspanelautoscroll

Change panel starting point


In my program i have a panel of 1000 by 1500 pixels, in that panel is a panel of 4000 by 10000 pixels which I can scroll through. Now this panel starts like in the left (example in the picture) but i was wondering if I could make it start like in the right example. And is it possible to change the 0,0 point of the Panel (picture in the link)

Panel i got and panel i want

Im using a derived Panel

class BufferedPanel : Panel
    {
        public BufferedPanel()
        {
            this.DoubleBuffered = true;
            this.ResizeRedraw = true;
        }
    }

Solution

  • You need to set the initial scroll position for the outer auto-scroll panel. To do so you can set AutoScrollPosition property of the outer panel. You should do it after the form is shown:

    protected override void OnShown(EventArgs e)
    {
        base.OnShown(e);
        panel1.AutoScrollPosition = new Point(0, 1250);
    }