I am building an application in which I want to display a button on a form. I want to display the Caption of the button on two lines. I have tried using the following code in the form's OnCreate event but it is not showing the new line.
Button.Caption := 'Hello' + #13#10 + 'world';
Any other method to add a new line?
Making multiple lines of text on a button is easy. Just insert <br /> to indicate where you want the lines to break.
The easiest way to have a line break is using the <br> tag on your text.
To make a multi-line text in UIButton, you insert a new line character ( \n ) wherever you want in button title and set lineBreakMode to byWordWrapping . You can adjust text alignment with . textAlignment .
Others have told you what you can do in code: set Wordwrap
and use SLineBreak
.
But I guess you'd like to edit the multiple lines in the designer. This is not possible in the plain IDE. There are a few 3rd party tools which allow it, but you can also simply use a '|'
to separate the lines, and then, in code use something like
Button1.Caption :=
StringReplace(Button1.Caption, '|', SLineBreak, [rfReplaceAll]);
(This is from memory, as I have no Delphi here, so please use the proper syntax).
In case you want to see to see the change in IDE, at design time, you can do the following:
'#13#10'
(CRLF). WordWrap
of the button control.Set WordWrap to True. That's all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With