FlowLayoutPanel-控件的自动宽度? [英] FlowLayoutPanel - Automatic Width for controls?

查看:590
本文介绍了FlowLayoutPanel-控件的自动宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使FlowLayoutPanel中插入的项目的大小自动达到FlowLayoutPanel的大小?这是一个示例:

is it possible to make the inserted items in FlowLayoutPanel automatic size of the FlowLayoutPanel? Here is an example:

具有1个FlowLayoutPanel和3个按钮的表单:

A form with 1 FlowLayoutPanel and 3 buttons inside:

如果我调整窗体的大小,控件将如下所示:它们从左到右排列

if I resize the form, the controls look like this: they arrange "left to right"

我想要的是:控件应具有FlowLayoutPanel的宽度:

What I want is this: The controls should have the width of the FlowLayoutPanel:

任何想法如何做到这一点?我更改了FlowDirection并使用了Anchor属性,但没有运气.

Any Ideas how to do this? I changed the FlowDirection and played with the Anchor property but with no luck.

我当然可以在FlowLayoutPanel_Resize事件中调整控件的大小,但是我想添加约500个用户控件-我对其进行了测试,而且速度很慢.

I could of course Resize the controls in the FlowLayoutPanel_Resize event, but I want to add about 500 usercontrols - I tested it and it is slow.

推荐答案

在这种情况下,建议您将TableLayoutPanel与一列一起使用.我发现TableLayoutPanel比FlowLayoutPanel更可预测和更可靠.

I suggest you using TableLayoutPanel with one column in this case. I have found TableLayoutPanel much more predictable and solid than FlowLayoutPanel.

如果仍然要使用FlowLayoutPanel,另一种选择是将第一个控件的宽度设置为所需的宽度,并对所有其他控件使用Dock = Top.

Another option, if you still want to use FlowLayoutPanel, is to set first control width to desired one, and use Dock = Top for all other controls.

这篇关于FlowLayoutPanel-控件的自动宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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