Is there any way to have textual content of controls on a TableLayoutPanel align themselves properly? I've got labels in column 0, and textboxes (or occasionally ComboBox or NumericUpDown controls) in column 1, but the text in the label is usually a pixel or two out (vertically) on most rows.
7 Answers
Select all the controls in your table layout panel. In the properties tab ensure anchor set to 'left'. I think it defaults to 'top,left'.
Hope that sets things straight.

- 151
- 1
- 2
-
Better and simpler. I found the same solution, but found your solution here already. – Aakash Jun 17 '17 at 09:38
-
For labels it is also useful to set the AutoSize Property to true else strings with whitespaces causing a line break. – Kinimod Oct 22 '19 at 09:03
I worked on it a few days back. I got everything as required. Try this:
For Labels
- Detach label from Tablelayoutpanel
- Set dockstyle to top
- Set anchor points none
TextAlign = MiddleLeft
- Then just place it in the table layout column
- Make sure the row style height matches label height if you have a label backcolor.
For Textboxes
- Detach textboxes from Tablelayoutpanel
- Set dockstyle to none
- Set anchor points none
TextAlign = MiddleLeft
(or as required)- Then just place it in the table layout column

- 30,738
- 21
- 105
- 131

- 11,332
- 27
- 76
- 122
You can set following properties:
for Label
1.Autosize= false;
2.TextAlign= MiddleLeft;
for Controls like Combobox,Textbox
goto View -> Toolbars -> Layout
Now you can give layout of your controls very easily by the Toolbar by selecting Multiple Controls at a Time............

- 15,024
- 26
- 81
- 118
I'd recommend leaving the anchors as they are and just adding a top margin to the controls that are too high. A margin of 3,6,3,0 is normal for me when I'm adding labels. As Javed said you can select multiple controls by control clicking. It irritates me that ComboBoxes are one pixel larger than Texboxes. Can't do much about that though.

- 596
- 1
- 4
- 9
Oh, you mean that text baseline for label is different than for other controls? If so, try to remove vertical anchors. You may play with margins as well.

- 18,366
- 7
- 57
- 79
-
Tried that, but it doesn't work with everything; Comboboxes are still badly aligned. – Flynn1179 Oct 06 '10 at 11:06
What I usually do is put them in a container eg a panel and anchor them relatively to that. The advantages of adding a container is you can also reduce the no of Win handlers. In that case that wouldn't matter , because you already have the TablelayoutPanel so basically for all the controls you only have a single handler.

- 829
- 1
- 10
- 26
You can try to use the modified TextBox instead of the Label: https://stackoverflow.com/a/75815030/2408668
This solution works also for the higher DPIs.

- 101
- 7