Flowlayout panel and autosizing child controls doesn't work

怎甘沉沦 提交于 2019-12-13 14:27:18

问题


I am trying to get a very simple autosizing layout on a winform (C# .NET). I've tried TableLayoutPanels and FlowLayoutPanels but nothing works.

I have a usercontrol which is a container for other usercontrols which are created at runtime - I've called it StackPanel as I want it to list the child controls vertically. I've tried this using a FlowLayoutPanel, TableLayoutPanel and a Panel (with each control docked to the top).

The child usercontrol consists of a label and then any number of radiobuttons (or any other standard control - it doesn't matter).

When the child controls are created, the label text is set (if this is long it needs to wrap to a new line) and the radio buttons are added.

There seems to be no combination of docking/autosizing or manual size setting using the Resize events that can get everything to show without clipping and still resize with the form.

Thanks!


回答1:


I've had a similar experience with both Panels.

FlowLayoutPanel:

You basically have to leave your child widgets anchored to the top left. Don't dock them. Also don't anchor them to the right. Label auto-sizing will only work in this configuration.

Then you can capture the resize event of the FlowLayoutPanel and manually adjust all the widths of your child components.



来源:https://stackoverflow.com/questions/2788648/flowlayout-panel-and-autosizing-child-controls-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!