Well, I have finally gotten to move into .NET development and actually right into .NET 2.0. Of course I'm writing in C#.
The WinForms project I'm working on has caused me to look into the FlowLayoutPanel and TableLayoutPanel that were added in 2.0. Those are pretty cool controls. The TableLayoutPanel is pretty much like the table element in HTML. You drag a TableLayoutPanel onto your form or UserControl and then drag other controls into each cell. You have a lot of powerful options for hooking the controls to the table. Docking and anchoring come into play for easily building an automatically resizing UI with little or no code. Automatically resizing two adjacent textboxes becomes a piece of cake. You use a table and set the columns to 50%, dock the textboxes (or a panel containing the texbox and it's caption label) and you're done.
The FlowLayoutPanel workes almost exactly like the items on an HTML page. When you drop several items in this control, it automatically arranges them in either a vertical or horizontal list. As you resize the panel, it shuffles the contained controls to fit inside the panel. Let's say you put 10 buttons in there. If the panel is wide enough, all the buttons are side-by-side in a horizontal row. As you resize the panel smaller, the buttons are rearranged into two (or more) rows as needed to fit. The panel has a setting for doing this top-down, bottom-up, right-to-left, and left-to-right.
Both of these controls have a padding property that sets the distance from the edges of the control or cell to the contained control. They also honor the margin property settings of the contained control. If both are supplied, they are added together. The FlowLayoutPanel uses the margins to set the gap between adjacent controls. It makes it very easy to build resizable content.
Some tricks I've used so far:
I needed to display four values like SubTotal, Tax, Shipping and Discount. The requirement was that if any of the values were 0 to not display that line. They wanted it squeezed up so each item was next to the others with no gaps for the missing values. (Note, this wasn't a real dynamic thing, just different for each order displayed.) What I did was to build a TableLayoutPanel much like you would in HTML. I put labels in column 1 and textboxes in column 2. I set the column and row styles to AutoSize and right-aligned the labels. Then in my setup method of the UserControl that contained this I put code to set the .Visible of the label and textbox for a row to false when the value was zero. A couple of lines of code. That was it. It takes longer to tell about than to do it. I now have a display that shows the values very similarly to below and automagically expands and collapses as needed:
(note that the total showed elsewhere on the screen)
Then since the grid above it showed the order items I placed another TableLayoutPanel on the outer control with only one column and two rows. The grid went into row one and the TableLayoutPanel into row two. I docked each of those in their cells and set row two to AutoSize and row one to 100% (which seems to mean 100% of the remaining after the autosized rows are calculated.) Now when the control is displayed the SubTotal, etc. sizes itself as necessary and then the grid is adjusted to take the remaining area. With no code (other than the visible settings of the label and textbox) I have a nice clean looking display. Cool!