当包含的控件太大时,如何使滚动条出现在可调整大小的面板中? [英] How to make scrollbars appear in a resizable panel when the contained control is too big for it?

查看:23
本文介绍了当包含的控件太大时,如何使滚动条出现在可调整大小的面板中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆