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


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01