Board index » delphi » Multi line in Button or Label

Multi line in Button or Label

How can I have a label or a push button display text in multiple lines?
 

Re:Multi line in Button or Label


Label1.Caption := 'First Line'#13'Second Line';

- Sunil Annam

Felix A. Hernandez <fe...@circuitvision.com> wrote in message
news:7va3uh$9ac20@forums.borland.com...

Quote
> How can I have a label or a push button display text in multiple lines?

Re:Multi line in Button or Label


Quote
"Sunil Annam" <s_an...@yahoo.com> wrote:
> Label1.Caption := 'First Line'#13'Second Line';

Out of sheer curiousity I tried this.

It works for a Label but not for a Button.

Why?

Also, every one of the constructs below worked for a Label but not a
Button - is this a Delphi bug?

procedure TForm1.FormShow(Sender: TObject);
begin

Button1.Caption :=  'First Line'#13'Second Line';
Button2.Caption :=  'First Line' + #13 + 'Second Line';
Button3.Caption :=  'First Line' + #10 + 'Second Line';
Button4.Caption :=  'First Line'#10#13'Second Line';
Button5.Caption :=  'First Line'#10'Second Line';
Button6.Caption :=  'First line' + #10#13 + 'Second Line';

Label1.Caption :=  'First Line'#13'Second Line';
Label2.Caption :=  'First Line' + #13 + 'Second Line';
Label3.Caption :=  'First Line' + #10 + 'Second Line';
Label4.Caption :=  'First Line'#10#13'Second Line';
Label5.Caption :=  'First Line'#10'Second Line';
Label6.Caption :=  'First line' + #10#13 + 'Second Line';
end;

Paul...

Quote
> - Sunil Annam

My newsreader can't cope with HTML - so if you
want my modest assistance, kindly post in ASCII.
If you don't care whether I read your posts or not,
by all means, post in HTML.

Re:Multi line in Button or Label


Quote
In article <38195a92.4526...@forums.inprise.com>, Paul Linehan wrote:
> Out of sheer curiousity I tried this.

> It works for a Label but not for a Button.

A button needs to be created with the BS_MULTILINE style to be able to
show multiple lines. This is easy to do, see below. The component
allows you to insert linebreaks in the designer by inserting a |
character.

unit MLButton;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
  StdCtrls;

type
  TMultilineButton = class(Tbutton)
  private
    FMultiline: Boolean;
    function GetCaption: String;
    procedure SetCaption(const Value: String);
    procedure SetMultiline(const Value: Boolean);
  public
    Procedure CreateParams( Var params: TCreateParams ); override;
    Constructor Create( aOwner: TComponent ); override;
  published
    property Multiline: Boolean read FMultiline write SetMultiline
default True;
    property Caption: String read GetCaption write SetCaption;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('PBGoodies', [TMultilineButton]);
end;

{ TMultilineButton }

constructor TMultilineButton.Create(aOwner: TComponent);
begin
  inherited;
  FMultiline := True;
end;

procedure TMultilineButton.CreateParams(var params: TCreateParams);
begin
  inherited;
  If FMultiline Then
    params.Style := params.Style or BS_MULTILINE;
end;

function TMultilineButton.GetCaption: String;
begin
  Result := Stringreplace( inherited Caption, #13, '|', [rfReplaceAll]
);
end;

procedure TMultilineButton.SetCaption(const Value: String);
begin
  If value <> Caption Then Begin
    inherited Caption := Stringreplace( value, '|', #13, [rfReplaceAll]
);
    Invalidate;
  End;
end;

procedure TMultilineButton.SetMultiline(const Value: Boolean);
begin
  If FMultiline <> Value Then Begin
    FMultiline := Value;
    RecreateWnd;
  End;
end;

end.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:Multi line in Button or Label


On Thu, 28 Oct 1999 14:21:54 -0400, "Felix A. Hernandez"

Quote
<fe...@circuitvision.com> wrote:
>How can I have a label or a push button display text in multiple lines?

To have a "push button" with a multi-line caption, you cannot use the
TButton component. Instead, use either the TBitBtn or the TSpeedButton
component (one can get focus, the latter cannot).

  BitBtn1.Caption := 'TBitBtn' + #10 + 'Component';

==========================================================================
Steve Koterski                  "Computers are useless. They can only give
Technical Publications          you answers."
Borland                                       -- Pablo Picasso (1881-1973)
http://www.borland.com/techpubs/delphi

Other Threads