Reputation: 115751
I'm writing a kind of "generic container dialog", which will ensure that all modal dialogs in an app will have the exact same "chrome" (namely, buttons, icons, etc.). I came up with the following:
The containerPanel
is just a System.Windows.Forms.Panel
.
Now what I want is as follows: for each dialog in an app, I want to create a separate UserControl
(not a full-blown Form
) and then "host" it inside this generic dialog. To do so, I need to somehow make this dialog self-adjustable so that it would shrink or grow depending on the size of a control hosted inside it.
How can I do that? Do I need some kind of layout control, or is there some special magical property to do this?
Upvotes: 3
Views: 5576
Reputation: 19956
You can iterate through Controls
collection and look for lower-bottom corner of every control that is enumerated, find maximum x and maximum y, and set form (container) Width and Height appropriately.
Upvotes: 1
Reputation: 2290
There is an boolean autosize property for windows.form.control . When true it allows the control to autosize automatically to fit its contents
Upvotes: 6