tags:

views:

2310

answers:

3

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.

+2  A: 

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

c.HorizontalScroll.Value += 100;
c.VerticalScroll.Value = c.VerticalScroll.Maximum;
bobwienholt
It works only when AutoScroll=true, but then I can't hide the HorizontalScroll/VerticalScroll. Setting the Scroll.Visible=false doesn't hide the scroll)
Jonas
A: 

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.

sindre j
don't think you can set the location to -ve values.
fallenidol
fallenidol : That is just plain wrong! Try it yourself, if you set the .Left property of a control to say -10 it will move left of the border of the container.
sindre j
+1  A: 

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.

Cyril Gupta