C#:如何让用户控件正确地自动调整大小控件、正确地、大小、用户

由网友(牙齿晒太阳)分享简介:我有一个 UserControl,它由一个 Label(顶部)、一个 FlowLayoutPanel(填充、TopDown 流和不换行)和一个面板(底部).用户控件根据获取的内容列表创建许多控件,并将它们添加到 FlowLayoutPanel.I have a UserControl which consists o...

我有一个 UserControl,它由一个 Label(顶部)、一个 FlowLayoutPanel(填充、TopDown 流和不换行)和一个面板(底部).用户控件根据获取的内容列表创建许多控件,并将它们添加到 FlowLayoutPanel.

I have a UserControl which consists of a Label (Top), a FlowLayoutPanel (Fill, TopDown flow and no wrap) and a Panel (Bottom). The user control creates a number of controls, based on a list of stuff it gets, and adds them to the FlowLayoutPanel.

我怎样才能让这个 UserControl 正确调整自身大小,使 FlowLayoutPanel 没有任何滚动条?我尝试在 FlowLayoutPanelUserControl 本身上使用 AutoSizeAutoSizeMode 的各种组合,但我可以似乎没有让它工作.要么我最终得到的东西根本不会自行调整大小,要么它没有变得足够大,要么它被压扁到几乎没有.

How can I get this UserControl to properly resize itself so that the FlowLayoutPanel does not have any scroll bars? I have tried to use various combinations of AutoSize and AutoSizeMode on the FlowLayoutPanel and the UserControl itself, but I can't seem to get it working. Either I end up with something that doesn't resize itself at all, or it doesn't become big enough or it is squished down to almost nothing.

推荐答案

感谢所有建议.这次的解决方案似乎将 FlowLayoutPanelUserControl 本身.

Thanks for all the suggestions. The solution this time seemed to set AutoSize to true for both the FlowLayoutPanel and the UserControl itself.

现在,如何获取将包含此 UserControl 以及其他一些控件的表单,目前我还不太清楚,但我想应该是一个单独的问题...

Now, how to get the form which will contain this UserControl as well as some other controls, that I can't quite figure out at the moment, but I guess that should be a separate question...