views:

536

answers:

3

I'm new to C# and I've been working on a small project to get the feel with Visual Studio 2008. I'm designing the GUI in C#, and I have a TabControl with three GroupBoxes. These three GroupBoxes are anchored to the left and right of the screen and work perfectly when resized horizontally.

I would like these three boxes to take up 33% of the height of the screen, and gracefully resize. I've tried messing around with anchoring, but I can't seem to find the answer. I've also been searching for something similar, but unfortunately, searching for positioning containers yields all CSS and HTML stuff.

This seems like a pretty common thing to do, but I can't seem to find an easy to way to do it. If someone could point me in the right direction, I'd greatly appreciate it.

Thanks!

A: 

Handle the form's Resize event: Add code to compute the new size/position of the controls in there. Beware to interferences with the controls' Anchor property. You may have to Anchor to None and compute left and right position yourself as well.

Since you're learning, I guess you prefer not to receive a full solution but rather a direction. No code from me then ;-)

Serge - appTranslator
A: 

This is really a shot in the dark but maybe you could try using split-panels ?

Edit: I've just checked in Visual Studio and I think the TableLayoutPanel might do what you want.

Edit2: dang, beaten to the punch :)

Led
Sorry about that ;) I was into split panels first as well, using the IsSplitterFixed property, but moved my mind to TableLayoutPanel when I realized that the split panel handles only two panels. Didn't like the thought of nesting them (while that would probably work).
Fredrik Mörk
+1  A: 

Try out the TableLayoutPanel. I believe it does exactly what you want. It allows you to define columns and rows within its area, specifying their width (for columns) and height (for rows) in percentages or pixels. You can then drop a group box into each cell and set its Dock property to Fill, and it will nicely resize along with the cell when the TableLayoutPanel resizes (which can be easily achieved by using docking or anchoring).

Fredrik Mörk
Thank you, that's exactly what I was looking for. It seems pretty obvious now, but I just missed that when looking at the containers!
Foo