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.


您应该可以使用组件的VerticalScroll和Horizo​​ntalScroll属性:

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

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.


    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.

    链接地址: http://www.djcxy.com/p/53688.html

    上一篇: Alpha Compact Framework 2.0中的Alpha混合颜色

    下一篇: 如何手动滚动面板?