C# 如何在Windows窗体中设置滚动条

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12313442/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 22:50:50  来源:igfitidea点击:

How to set scroll bar in Windows form

c#.net

提问by user1448783

I have a winform in .net and I place too many controls and set the height and width of form. But when I compile the form and decrease the size of form my controls are not visible. When I increase the size of form the controls are visible at their own places.

我在 .net 中有一个 winform,我放置了太多控件并设置了表单的高度和宽度。但是当我编译表单并减小表单的大小时,我的控件不可见。当我增加表单的大小时,控件在它们自己的位置可见。

I want a scroll bar to appear when I decrease the size of form and the scroll bar to disappear when we increase the form size.

我希望当我减小表单大小时出现滚动条,当我们增加表单大小时滚动条消失。

回答by adatapost

Set trueto AutoScrollproperty of Form.

设置trueAutoScrollForm 的属性。

回答by Sethu

You need to use the Panel control as container of your child controls and set "AutoScroll" property to true.

您需要使用 Panel 控件作为子控件的容器并将“AutoScroll”属性设置为 true。

回答by Nitesh

You can use Panel, TabControl or SplitContainer control as container and place all of you contros into it. Set the AutoScroll property of Panel control to true for getting scroll bar on the form. Dock the Panel control to Fill so that it appear on entire form.

您可以使用 Panel、TabControl 或 SplitContainer 控件作为容器并将所有控件放入其中。将 Panel 控件的 AutoScroll 属性设置为 true 以获取窗体上的滚动条。将 Panel 控件停靠到 Fill,以便它出现在整个表单上。

Thanks.

谢谢。

回答by Pir Fahim Shah

Write this code in your Form LOAD EVENT, and you will get your scroll bar, like i am writting it here in my Form Load Event.

在您的表单加载事件中编写此代码,您将获得滚动条,就像我在表单加载事件中编写的那样。

private void Form1_Load(object sender, EventArgs e)
    {    
        Panel my_panel = new Panel();
        VScrollBar vScroller = new VScrollBar();
        vScroller.Dock = DockStyle.Right;
        vScroller.Width = 30;
        vScroller.Height = 200;
        vScroller.Name = "VScrollBar1";
       my_panel.Controls.Add(vScroller);
      }

回答by jeetendra singh negi

Add all control of your windows form in a panel, write the following code in your window form Load event and set the auto scroll property of your window form to true.

在面板中添加窗体的所有控件,在窗体的 Load 事件中编写以下代码并将窗体的自动滚动属性设置为 true。

  private void Form1_Load(object sender, EventArgs e)
    {

        Panel my_panel = new Panel();
        VScrollBar vScroller = new VScrollBar();
        vScroller.Dock = DockStyle.Right;
        vScroller.Width = 30;
        vScroller.Height = 200;
        vScroller.Name = "VScrollBar1";
        my_panel.Controls.Add(vScroller);
    }

回答by Faraz Ahmed

There is one thing which have to be remember is that,

有一件事必须记住的是,

Set true to AutoScroll property of Form.

将 Form 的 AutoScroll 属性设置为 true。

is run, when forms have controls till end of height, If end of forms doesn't contain any control and there is only space on it, then this AutoScroll Property doesn't work.

运行时,当表单具有控件直到高度结束时,如果表单末尾不包含任何控件并且上面只有空间,则此 AutoScroll 属性不起作用。