Einzelnen Beitrag anzeigen

jottkaerr

Registriert seit: 2. Jul 2007
Ort: Tuttlingen
81 Beiträge
 
Delphi 10.1 Berlin Professional
 
#21

Re: TLabel + taRightJustify = katastrophe?

  Alt 24. Okt 2007, 12:38
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  l := tLabel.Create(self);
  l.Left := 300;
  l.Alignment := taRightJustify;
  l.Parent := Self;
  l.Top := 3;

  Showmessage('Left: ' + IntToStr(l.Left) + ' Width: ' + IntToStr(l.Width));
  l.Caption := 'Hallo Welt';
  Showmessage('Left: ' + IntToStr(l.Left) + ' Width: ' + IntToStr(l.Width));
end;
die erste Ausgabe ergibt "Left: 300 Width: 65". "65" ist also die Default-Breite eines (leeren) Labels. Wenn Du jetzt l.Caption den neuen Text zuweist, erhältst Du "Left: 316 Width: 49". Der Text ist als kürzer als die bisherige Breite, und daher wird (bei rechtsbündiger Ausrichtung) der Anfang des Labels nach rechts verschoben.

jkr
Jürgen Krämer
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
  Mit Zitat antworten Zitat