Center text alignment for labels

I have a label exactly in the center of the form with the text "This is my Visual Studio application." Now I have a button click event that changes the text to “My application”. But the problem is that the alignment is broken, because the length of the modified text is different from the previous one. I tried the TextAlign label option for MiddleCenter. but no luck. Can anyone help?

+7
source share
3 answers

You will also need to set the width of the label to the length of your longest text, or simply to the width of the form.

+5
source

You can even do better: set the Autosize OFF label and manually stretch the shortcut in the designer to fill the area needed to display the largest text value. Now, if you set TextAlign to MiddleCenter, you will get the desired effect (even in the designer, so you can check it by setting the value in the Text property).

+9
source

You need to set the label autosize parameter to true, place this label inside the frame (or table cell) and set the binding properties to zero. Thus, it will always be centered.

0
source

All Articles