Jonas
Jonas

Reputation: 1373

How to scroll a panel manually?

I want to use the same functionality available when a Panel.AutoScroll is true, but with the scrollbars invisible.

To do so I need to know how can I scroll to left/right up/down using functions in my code.

Upvotes: 16

Views: 33654

Answers (3)

Cyril Gupta
Cyril Gupta

Reputation: 13723

Well if you don't want to use the Autoscroll property, there's a way that I used a long time ago.

  • Put a panel inside the panel. Put the scrollbar control on the parent panel, and then use the scrollbar to change the Top property of the panel inside.

It's simple and works beautifully.

Upvotes: 10

sindre j
sindre j

Reputation: 4444

There's probably a property on the panel to do this, alternatively you can loop through all the panels children and adjust their positions.

Eg. to move all controls 10 px:

int xoffset = 10;

foreach(Control c in panel1.Controls)
    c.Location.X += xoffset;

The controls can be moved to negative positions to make them move out of the panel, similarly they can have location values bigger than the panels size to make them move out of the panel.

Upvotes: -3

bobwienholt
bobwienholt

Reputation: 17610

You should be able to use the VerticalScroll and HorizontalScroll properties of the component:

c.HorizontalScroll.Value += 100;
c.VerticalScroll.Value = c.VerticalScroll.Maximum;

Upvotes: 13

Related Questions