Docking/Anchoring controls
-
I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.
-
I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.
Have you looked at adding a SplitContainer into the mix? I'm thinking that if you dock one panel on the left side of the form (or control), dock a second panel in the upper-right, a third panel in the bottom right, and place a SplitContainer into an area you leave open between the two panels docked on the right, then you can place your #3 and #4 controls in the split container panels, and not worry about any overlap. You could set the IsSplitterFixed property to True to prevent the user from resizing the split, and make the splitterwidth small enough that it is unseen. Anyways, that is one idea, I won't be surprised if there are better ideas...
-
I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.
yep, do it hierarchically, i.e. split your form in two parts (that would be 1 versus 2+3+4+5) using either a SplitContainer or two Panels; give those the right anchoring. Then iterate for the next split (5 versus 2+3+4). Etc. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
I have a user control (which for the purposes of this post is just a container), and several nested user controls. I want to lay out the child controls inside the container in a similar way to the following picture: http://mi6.nu/docking.jpg I've tried different combinations of Anchor and Dock properties as well as using a Flow Layout Panel, but I can't get it to work. The two things I know are: 1) The location of each child control on the Y-axis 2) The height of the control I need some way to assign these controls a combination of properties and have them stack up as shown in the picture. Full width child controls should float to the left, and if there's more than one child control at a Y location (eg: 3 and 4), the available space should be split. I managed to get it sort of working, but items were overlapping.
-
Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.
I don't know which Control would help you split a distance in N equal parts, N being possibly larger than 2 and not a power of 2. The way I used to do all these things, before I was even aware of anchoring and SplitContainers, is by calculating Top, Left, Height and Width myself, by code, in the OnResize handler. Takes some code, but does exactly what you want with no additional Controls to achieve your layout. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Voting for dummies? No thanks. X|
-
Thanks for the quick response. I didn't explain myself very well. The number of child controls isn't a fixed value. In the example there are two items with the same Y value, but there may be just one, or four or five.
-
I still do it the way that Luc mentioned in his post above. It's alot more code but it leaves you in control!
Dave