Recent

Author Topic: Are there TButton equivalents whose labels support word wrap?  (Read 3928 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Are there TButton equivalents whose labels support word wrap?
« on: February 07, 2013, 06:40:26 pm »
Are there TButton equivalents whose labels support word wrap?
Lazarus 3.0/FPC 3.2.2

Luke Snowmaker

  • New Member
  • *
  • Posts: 11
  • "Who are you...?" -"Nobody..."
Re: Are there TButton equivalents whose labels support word wrap?
« Reply #1 on: February 08, 2013, 10:03:14 pm »
Hi there,
actually, you can put a standard TButton without a caption on your form and then implement the following code into the FormCreate event:

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'first' + #13#10 + 'second' + #13#10 + 'third';
end;

At the end, you get a button with three lines...is that what you meant...?

cheers..!
« Last Edit: February 08, 2013, 10:05:42 pm by Luke Snowmaker »
openSUSE 12.2
Lazarus IDE 1.0.4/FPC 2.6.0

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Are there TButton equivalents whose labels support word wrap?
« Reply #2 on: February 08, 2013, 10:08:18 pm »
Are there TButton equivalents whose labels support word wrap?

Try the solution above on a TSpeedButton.

vfclists

  • Hero Member
  • *****
  • Posts: 1013
    • HowTos Considered Harmful?
Re: Are there TButton equivalents whose labels support word wrap?
« Reply #3 on: February 09, 2013, 03:09:56 am »
This is rather awkward because the need for word wrap can only be computed when the size of the text is known. It has been available since Delphi 7.
Isn't the label on a button a stand label which can be set to word wrap even if it means subclassing TButton?

Can a message be sent to it that will effect the wordwrap, it is needed?

Hi there,
actually, you can put a standard TButton without a caption on your form and then implement the following code into the FormCreate event:

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'first' + #13#10 + 'second' + #13#10 + 'third';
end;

At the end, you get a button with three lines...is that what you meant...?

cheers..!
Lazarus 3.0/FPC 3.2.2

Luke Snowmaker

  • New Member
  • *
  • Posts: 11
  • "Who are you...?" -"Nobody..."
Re: Are there TButton equivalents whose labels support word wrap?
« Reply #4 on: February 09, 2013, 11:24:19 am »
if its so necessary, you can try this using BitBtn (instead of OnClick, you can use Form OnCreate event, or if you need it realtime, Id use a timer OnTimer event):

Code: [Select]
procedure TForm1.BitBtn1Click(Sender: TObject);
  var S: AnsiString;
    R: TRect;
    stl:TTextStyle;
begin
    S:='Hello World Hello World Hello World Hello World';
    BitBtn1.Glyph.Canvas.Font := BitBtn1.Font;
    BitBtn1.Glyph.Width := BitBtn1.Width - 6;
    BitBtn1.Glyph.Height := BitBtn1.Height - 6;
    R := Bounds(0, 0, BitBtn1.Glyph.Width, BitBtn1.Glyph.Height);
    BitBtn1.Caption := '';
    BitBtn1.Glyph.Transparent:=false;
    BitBtn1.Glyph.Canvas.Brush.Color:=clBtnFace;
    BitBtn1.Glyph.Canvas.FillRect(R);
    stl.Alignment:=taCenter;
    stl.Wordbreak:=true;
    stl.Layout:=tlCenter;
    stl.SingleLine:=false;
    R := Bounds(1, 1, BitBtn1.Glyph.Width-1, BitBtn1.Glyph.Height-1);
    BitBtn1.Glyph.Canvas.TextRect(R,0,0,S,stl);
end;                               

This works for me.
openSUSE 12.2
Lazarus IDE 1.0.4/FPC 2.6.0

 

TinyPortal © 2005-2018