Delphi: Center the Text on a Label vertical and horizontal
Question by Guest | Last update on 2021-04-19 | Created on 2012-08-27
I want to center the caption of a TLabel vertically and horizontally, the text should therefore appear exactly in the middle, when I change the size of the label.
However, the text is always sticking at the top. But instead, the text should always be in the middle, just as it is with the panel (TPanel). How can I achieve this? Unfortunately, I can not find a property for VerticalAlign with the label.
Related Topics
Lord's Prayer in 20 other Languages
Info | 0 Comments
Delphi/Lazarus: Dynamically create a Label at runtime
Tip | 0 Comments
HTML5 Canvas: Center Text on Point horizontally and vertically
Tutorial | 0 Comments
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
Delphi/Lazarus: How to set up a Link to a Website in an Application
Tutorial | 0 Comments
Delphi: Multiline Caption for TLabel (at Run Time and Design Time)
Tutorial | 1 Comment
Total Lunar Eclipses in Germany - Dates
Info | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You just have to set the properties of "Alignment" and "Layout" in the Object Inspector or the code to centered. In the code, that is looking like this:
Alignment ensures the horizontal alignment, Layout provides the vertical alignment.
Under certain circumstances, you have also to set "AutoSize" to "False", in order to prevent the reset of the size of the label.
Last update on 2021-04-19 | Created on 2012-08-28
It dosn't work.
Working solution:
and "AutoSize" to "False".
2013-11-26 at 12:02
But the .Left and .Top properties of the label have no effect to the alignment of the text of the label.
And .Width - .Witdh is always zero leading to exceptions as it is also for .Height - .Height.
2013-11-26 at 15:05