citronas
citronas

Reputation: 19365

How to create a layout with top-floating controls and autosize?

I'm currently stuck at creating a layout for a WinForms Control:

My usercontrol hosts the following subcontrols:

RichTextBox
Label B
  Control B
  Control B
  Control B
Label C
  Control C
  Control C
Label D
  Control D
  Control D

The RichTextBox is always visible. It's height should grow as big as it needs to be to display all text without ScrollBars.

Depending on my dataobject, I want to display several additional information if present. For instance, there can be 5 controls B, 0 C and 20 D.
I want the controls to "float" to the top. Each control should be able to grow in height in order to display it's full content.

I've tried numerous combinations of TableLayoutPanels, FlowLayoutPanels, docking and autosize settings, but none of them fulfilled my expectations.

How can I arrange my controls in the order I posted above with the features dock top and autosize?

Upvotes: 2

Views: 1422

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

  1. Create outer TableLayoutPanel with 4 rows and 1 column. Set SizeType = AutoSize for rows.
  2. Place RichTextBox into first row.
  3. Create inner TableLayoutPanel with so many rows, as your controls count, and 2 columns. Set SizeType = AutoSize for all rows. Set AutoSize = true for inner TableLayoutPanel. Place it to next row.
  4. Place Label to first cell. Set ColumnSpan = 2 for lable.
  5. Place controls into second column of other rows.
  6. Repeat 3-5 for other inner B and C

Upvotes: 4

Related Questions