Reputation: 1090
I have a Label in Windows Forms which has a specific text and size and has the property autosize set to true. I try to set his location to the center, but while using this code, it doesn't fit to the center of the form.
Label lab = new Label();
lab.Text = "blablabla";
lab.Font = new Font("Segoe UI", 32);
lab.Autosize = true;
lab.Location = new Point(ClientSize.Width / 2 - lab.Width / 2, 0);
this.Controls.Add(lab);
Upvotes: 1
Views: 1847
Reputation: 77876
If it's Winform then set AutoSize
to false
lab.Autosize = false;
along with that set the TextAlign
property to MiddleCenter
lab.TextAlign = MiddleCenter
and choose Fill
for the docking property.
Upvotes: 2