Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline character in caption of button

Tags:

delphi

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?

like image 972
naren Avatar asked Aug 02 '11 13:08

naren


People also ask

How do you make a multiline button?

Making multiple lines of text on a button is easy. Just insert <br /> to indicate where you want the lines to break.

How to put a button on a new line in html?

The easiest way to have a line break is using the <br> tag on your text.

How to set multiline text in button in swift?

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 .


3 Answers

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).

like image 58
Rudy Velthuis Avatar answered Nov 01 '22 07:11

Rudy Velthuis


In case you want to see to see the change in IDE, at design time, you can do the following:

  1. Right click in the control and select "View as Text".
  2. Locate the control and at the spot you want the line break, add to the value of Caption, the characters '#13#10' (CRLF).
  3. Right click and select "View as Form".
  4. Check the property WordWrap of the button control.
like image 33
stmpakir Avatar answered Oct 06 '22 00:10

stmpakir


Set WordWrap to True. That's all.

like image 11
NGLN Avatar answered Nov 01 '22 07:11

NGLN