开发者

Autosizing WinForms Dialog to fit inner content

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 f开发者_运维知识库ollowing:

Autosizing WinForms Dialog to fit inner content

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?


There is an boolean autosize property for windows.form.control . When true it allows the control to autosize automatically to fit its contents


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜