当包含的控件太大时,如何使滚动条出现在可调整大小的面板中?

How to make scrollbars appear in a resizable panel when the contained control is too big for it?(当包含的控件太大时,如何使滚动条出现在可调整大小的面板中?)
本文介绍了当包含的控件太大时,如何使滚动条出现在可调整大小的面板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Windows 窗体应用程序(.NET 2.0,VS 2005).我有一个表单,它本质上包含一个使用表单动态调整大小的面板:

I am developing a Windows Forms application (.NET 2.0, VS 2005). I have a form that essentially contains a panel that is dynamically resized with the form :

this.panel1.Dock=DockStyle.Fill;

此面板仅用作容器.在运行时,将添加一个自定义控件:

This panel is simply used as a container. At runtime, a custom control will be added :

UserControl uc=new UserControl();
panel1.Controls.Add(uc);
uc.Dock=DockStyle.Fill;

由于此自定义控件有最小尺寸要求,如果滚动条太小而无法显示整个控件,我希望滚动条出现在包含面板上:

As this custom control has a minimum size requirement, I want scroll bars to appear on the containing panel if it gets too small to show the entire control :

this.panel1.AutoScroll=true;

这不起作用.我尝试使用 Anchor 属性而不是 Dock 属性来调整面板的大小,但无济于事.

This does not work. I have tried to resize the panel using the Anchor property rather than the Dock property, to no avail.

推荐答案

不要停靠你的用户控件.请改用 Anchor 属性.(锚定到所有四个侧面).设置用户控件的 MinimumSize 属性设置面板的 AutoScrollMinSize 属性

Don't Dock your User control. Use the Anchor property instead. (Anchor to all four sides). Set you User control's MinimumSize property Set the panel's AutoScrollMinSize property

除非您设置它的 AutoScrollMinSize 属性,否则面板的滚动条不会出现.将用户控件的 Dock 设置为 Fill 似乎隐藏了面板的滚动条.

The Panel's scrollbars won't appear unless you set its AutoScrollMinSize property. Setting the user control's Dock to Fill seems to hide the panel's scrollbars.

这篇关于当包含的控件太大时,如何使滚动条出现在可调整大小的面板中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)