简体   繁体   English

无法滚动到WinForm的底部

[英]Unable to scroll to the bottom of WinForm

I am using visual studio 2012 for this. 我为此使用Visual Studio 2012。 Basically I have a WinForm that I want to expand. 基本上,我有一个要扩展的WinForm。

Inside the form designer, I am able to see that my form has a scroll bar, but when I compile the program, the scroll bar does not appear. 在表单设计器内部,我可以看到我的表单具有滚动条,但是在编译程序时,滚动条不会出现。 The controls that are beyond my screen size are clipped off, as opposed to having a scrollbar. 屏幕尺寸之外的控件被剪切掉,而不是具有滚动条。

Are there any settings that I have missed out? 有没有我错过的设置? Currently I set my AutoScroll = true. 当前,我将AutoScroll设置为true。

Scrollbars show up when a parent control has the AutoScroll set to true and a child control has a MinimumSize such that the client area of the child control is larger than the client area of the parent control. 当父控件的AutoScroll设置为true且子控件的MinimumSize使得子控件的客户区大于父控件的客户区时,将显示滚动条。

Eg 例如

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    var sampleForm = new Form() { AutoScroll = true };

    Panel panel = new Panel() { BackColor = Color.Red, AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoSize = true };
    Button btn = new Button { Text = "Toggle MinSize", AutoSize = true };
    panel.Controls.Add(btn);

    btn.Click += delegate {
        if (panel.MinimumSize == Size.Empty)
            panel.MinimumSize = new Size(600,600);
        else
            panel.MinimumSize = Size.Empty;
    };

    sampleForm.Controls.Add(panel);
    Application.Run(sampleForm);
}

If your child panel correctly calculates its preferred size, then you can override the MinimumSize property and return the PreferredSize . 如果您的子面板正确计算了其首选大小,则可以覆盖MinimumSize属性并返回PreferredSize

AutoScroll = true is enough to display scroll on form no other setting is required. AutoScroll = true足以在不需要其他设置的情况下显示滚动。

just try other thing add panel in form and set panels AutoScroll = true and then add control to it and check that scroll is working or not ? 只是尝试其他方法在窗体中添加面板并设置面板AutoScroll = true,然后向其添加控件并检查滚动是否正常?

Take a look at the properties of the controls within the container for which you want autoscroll to work. 查看您要自动滚动对其进行操作的容器中控件的属性。 One possibility is that you set one or more of those controls Anchor property to Right or something, which can reverse the autoscroll setting behind the scenes to effectively turn it off. 一种可能是将其中一个或多个控件的Anchor属性设置为Right或其他,这可以在后台反转自动滚动设置以有效地将其关闭。 Also check the RightToLeft property of the container, and try setting that to the default "no" 还要检查容器的RightToLeft属性,并尝试将其设置为默认的“ no”

Make sure you have set Dock.Fill ie Dock property to Fill Set property AutoScroll = true , AutoSize = true, AutoSizeMode = GrowOnly ,you can also do this by adding a panel to the form and set panel AutoScroll = true. 确保已将Dock.Fill即Dock属性设置为Fill Set属性AutoScroll = true,AutoSize = true,AutoSizeMode = GrowOnly ,也可以通过向面板添加面板并将面板设置为AutoScroll = true来做到这一点。 compare your issue with example here 将您的问题与此处的示例进行比较

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM