Recent

Author Topic: [SOLVED] RightJustify text in TLabel  (Read 2995 times)

tudi_x

  • Hero Member
  • *****
  • Posts: 532
[SOLVED] RightJustify text in TLabel
« on: August 25, 2017, 05:48:38 pm »
hi All,
please advise how i could align on the right side the text in a label. as per the below i cannot get this alignment in TLabel. in TEdit is working.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   l: TLabel;
  4.  
  5. begin
  6.   l := TLabel.Create(self);
  7.   l.Parent := self;
  8.   l.Caption := 'xxxx';
  9.   l.Visible := True;
  10.   l.Top := 50;
  11.   l.Color := clYellow;
  12.   l.Alignment:=taRightJustify;
  13.  
  14.   l.Left := self.Width - l.Width;
  15.   Form1.Caption:= inttostr(self.Width) + '|' + inttostr(l.Width) + '|' + inttostr(l.Left);
  16. end;

thank you
(Windows 7 Lazarus 1.8RC4 64b)
« Last Edit: August 25, 2017, 06:15:04 pm by tudi_x »
Lazarus 2.0.2 64b on Debian LXDE 10

balazsszekely

  • Guest
Re: RightJustify text in TLabel
« Reply #1 on: August 25, 2017, 05:56:10 pm »
Set AutoSize to false...

tudi_x

  • Hero Member
  • *****
  • Posts: 532
Re: RightJustify text in TLabel
« Reply #2 on: August 25, 2017, 06:14:39 pm »
thank you!
it worked

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   l: TLabel;
  4.  
  5. begin
  6.   l := TLabel.Create(self);
  7.   l.Parent := self;
  8.   l.Caption := 'xxxx';
  9.   l.Visible := True;
  10.   l.Top := 50;
  11.   l.Color := clYellow;
  12.   l.Alignment:=taRightJustify;
  13.   l.AutoSize:= false;
  14.  
  15.   l.Left := self.Width - l.Width;
  16.   Form1.Caption:= inttostr(self.Width) + '|' + inttostr(l.Width) + '|' + inttostr(l.Left);
  17. end;  
Lazarus 2.0.2 64b on Debian LXDE 10

Arend041

  • New Member
  • *
  • Posts: 16
Re: RightJustify text in TLabel
« Reply #3 on: March 09, 2022, 09:27:59 pm »
Set AutoSize to false...
It does indeed work (version 2.0.12 also), but the width is sometimes not sufficient, so that sometimes the label text is not displayed in full.
I hope this 'bug' will be fixed one day. StaticText has the same problem.

dsiders

  • Hero Member
  • *****
  • Posts: 1077
Re: RightJustify text in TLabel
« Reply #4 on: March 09, 2022, 10:08:11 pm »
Set AutoSize to false...
It does indeed work (version 2.0.12 also), but the width is sometimes not sufficient, so that sometimes the label text is not displayed in full.
I hope this 'bug' will be fixed one day. StaticText has the same problem.

Perhaps you just need to use the WordWrap property.

https://dsiders.gitlab.io/lazdocsnext/lcl/stdctrls/tcustomlabel.wordwrap.html

Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

wp

  • Hero Member
  • *****
  • Posts: 11910
Re: RightJustify text in TLabel
« Reply #5 on: March 09, 2022, 10:24:30 pm »
Set AutoSize to false...
It does indeed work (version 2.0.12 also), but the width is sometimes not sufficient, so that sometimes the label text is not displayed in full.
I hope this 'bug' will be fixed one day. StaticText has the same problem.
This is no bug. You turned AutoSize off, and therefore it is your responsibility to set the label wide enough so that the text is not truncated.

 

TinyPortal © 2005-2018