C#: How to get a user control to properly auto size itself

Svish picture Svish · Aug 31, 2009 · Viewed 71.6k times · Source

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.

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.

Answer

Svish picture Svish · Aug 31, 2009

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

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...