Child controls of a TableLayoutPanel expand to fill their cell when Anchor includes R

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
Hi

I have a TableLayoutPanel whose ColumnStyles are set to:

1st column = 200 pixels absolute
2nd column = (remainder/autosize)


I find that child controls added to the second column expand to fill it when Anchor setting includes right - i.e. their behaviour is more like Dock = Fill

What I'm after, is for them to be e.g. 200 pixels wide in the 500 pixel wide column. When the column expands to 600 pixels, the control should grow to 300 pixels (i.e. use 100% of the 100px expansion, but not 100% of the space)

Any ideas? Must I create a third column of width 300, to which nothing is added?
 
Anchor left+right = horizontal fill is by design.

Suggestion:
1st column = 200 pixels absolute
2nd column = 100% percent (=200px in Designer) expands when TLP is anchored.
3rd column = 300 pixels absolute (some controls also spans to this? just spacing to 4th column?)

You could also set the right margin for the control you don't want to fill whole cell when anchored/docked.
 
thanks john - i couldnt work out why the horizontal filling occurred because for a normal control dumped on e.g a form, it doesnt

I stumbled upon the same result as you posted after scratching my head for a few hours - I had the second column set to autosize.. which seems to make it occupy all the remaining space and squish any columns after it.. somewhat counterintuitive in my opinion! ;)
 
Back
Top