Dynamic control layout
I'm trying to build a rather complex UI and minimize unused space.
I have an unknown number of controls and I'd like to group them into panels. All of these panels should be开发者_开发百科 added to a parent panel.
So, it might be something like a single parent panel which contains 6 child panels. One of these 6 might have 2 checkboxes and a textbox. Another might have 3 dropdowns, etc. I won't know at design time. It also may be the case that I need the child panels to show up in a specific order instead of what would be optimal for saving space.
I tried to play around with FlowLayout for both the parent panel and the child panels. I think that will be part of the solution, but I don't know quite what to do. I thought about testing every possible combination of flowbreaks and pick the combination where the parent panel height is the smallest, but that is too computationally intensive.
Are there any resources that cover this sort of thing? Or maybe my approach is wrong? I think my users are going to want the controls packed as close as possible, but with the grouping. If it weren't for trying to group them, I might be able to get by with a single parent FlowLayout panel.
I think the problem is almost like the packing problem, but it's more like a packing problem within a packing problem due to the grouping.
Just a quick note on generating Dynamic controls in a specific layout. I assume you will be loading the data for your controls from some data source. It will really simplify your life if you can add a few columns of data to your source for
GroupID
and SortOrder
, both can be simple int fields.
Whenever I have done dynamic layouts I have found its much easier to write universal insert logic if you have some order to the data. The group and sort can then be switched around in the data without having to re-write some crazy case statements in the code that you would otherwise have to write.
精彩评论