Delphi: Panel with multi-line centered Caption
Question by Guest | 2012-08-04 at 16:43
I want to write a text on a panel in a Delphi program. However, this text should be centered horizontally and vertically, and above all, it has to be multiline.
At the moment, I am trying to set the caption of the panel with the following code to a multi-line text:
Panel1.Caption := 'Line 1' + #13 + #10 + 'Line 2';
However, this does not work for some unknown reason. The new line defined with #13#10, works all the time in other contextes, but not here. What am I doing wrong?
Related Topics
Delphi: Multiline Caption for TLabel (at Run Time and Design Time)
Tutorial | 1 Comment
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
Rewrite Text Files with a fixed Line Length
Tutorial | 0 Comments
Repair Text Files with mixed Line Breaks
Tutorial | 0 Comments
Delphi/Lazarus: Add Item or Line to ListView
Info | 0 Comments
RTF: Align Text - Left, Right, Centered and Justified
Info | 1 Comment
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.
Unfortunately, TPanel does not support multi-line captions, at least not in the newer versions of Delphi. To be able to display the caption of the panel with several lines, you have to write a custom component derived from TPanel and rewrite the OnPaint event.
But it is easier to do it like this: Simply put a TLabel on the panel, and format it as follows:
Of course, you can also use the Object Inspector to set the properties (except the #13#10).
Explanation: With "Align", the label is extended, so that it occupies the entire size of the panel. With this, however, the inscription of the label would only be seen at the top. We do not want that, so we set "Alignment" to "taCenter" and "Layout" to "tlCenter" to center the words on the label. Finally, we can still set "WordWrap" to "True", so the text on the label wraps automatically. Naturally, the caption of the panel underneath, should contain no text.
2012-08-04 at 22:14