C# 如何手动滚动面板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/262534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to scroll a panel manually?
提问by Jonas
I want to use the same functionality available when a Panel.AutoScroll is true, but with the scrollbars invisible.
我想在 Panel.AutoScroll 为真时使用相同的功能,但滚动条不可见。
To do so I need to know how can I scroll to left/right up/down using functions in my code.
为此,我需要知道如何使用代码中的函数向左/向右向上/向下滚动。
回答by bobwienholt
You should be able to use the VerticalScroll and HorizontalScroll properties of the component:
您应该能够使用组件的 VerticalScroll 和 HorizontalScroll 属性:
c.HorizontalScroll.Value += 100;
c.VerticalScroll.Value = c.VerticalScroll.Maximum;
回答by sindre j
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:
例如。将所有控件移动 10 像素:
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.
控件可以移动到负位置以使其移出面板,类似地,它们的位置值可以大于面板大小以使其移出面板。
回答by Cyril Gupta
Well if you don't want to use the Autoscroll property, there's a way that I used a long time ago.
好吧,如果您不想使用 Autoscroll 属性,那么我很久以前就使用过一种方法。
- 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.
- 在面板里面放一个面板。将滚动条控件放在父面板上,然后使用滚动条改变面板里面的Top属性。
It's simple and works beautifully.
它很简单,而且效果很好。