gonzobrains
gonzobrains

Reputation: 8036

Label control not filling its containing cell in TableLayoutPanel

What could cause a Label control to not grow/shrink to its containing cell inside of a TableLayoutPanel? I have a few TableLayoutPanels inside another encompassing TableLayoutPanel. I need the Label controls within the cells to adjust their size when the form is resized. Button controls do this but Label controls do not.

I tried a simple experiment with Label controls in a more simpler example that uses just one TableLayoutPanel and it works; the Label controls resize fine when I set the Dock property to "fill," but I can't get it working in the form that has multiple TableLayoutPanel controls embedded within another one.

Microsoft suggests one should avoid nesting here:

http://msdn.microsoft.com/en-us/library/ms171689.aspx

However, I need to be able to make separate groups of controls within a TableLayoutPanel. Can anyone provide some insight?

Upvotes: 0

Views: 3291

Answers (1)

Adam Maras
Adam Maras

Reputation: 26863

Have you set the Label.AutoSize property of your labels to false? Per MSDN's documentation on the AutoSize property (emphasis mine):

The Dock and Anchor properties are honored when AutoSize is true.

The value of the control's Location property is adjusted to the correct value.
Note The Label control is the exception to this rule. When you set the value of a docked Label control's AutoSize property to true, the Label control will not stretch.

Upvotes: 3

Related Questions