Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center labels in Tablelayoutpanel

Tags:

c#

I Can not get Labels to "Snap" to The Center of a cell in Tablelayoutpanel. I tried to Set The anchor to none in the Tablelayoutpanel.TextAlign to center & AutoSize to false in the Label before dragging it to the Tablelayoutpanel,no joy.The Label just stays at the top left?I want the Label to align with the TextBox I have in it.

Is their some kinda trick to this? or should i be using a other layout panel?

like image 645
DarkPh03n1X Avatar asked Aug 01 '14 11:08

DarkPh03n1X


People also ask

How do I center a label in VB net?

Set the Autosize property of your label to False, then either Dock the Label Top, Bottom or Fill, or drag it to the full width of the form and set Anchor to both Left and Right. Then set TextAlign to MiddleCenter.

How do you put a label in the middle of a panel?

Anchor the panel in the center of the form, set it to 1 row and 1 column, put your label in the cell and set the anchor on the label to None. With that done the label will "float" in the center of the panel.


2 Answers

Just replace Anchor property of the label from Top, Left to None. Set None

like image 122
pot Avatar answered Sep 25 '22 01:09

pot


You should do the following:

  1. Set label AutoSize = false.
  2. Set label Anchor to (Left | Right | Top | bottom)
  3. Set Label Text Alignment to Middle-Center..

Worked for me..

like image 31
Sourav Gupta Avatar answered Sep 25 '22 01:09

Sourav Gupta