AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

neue Komponente : "TlabeledLabel"

Ein Thema von Hansa · begonnen am 29. Mär 2005 · letzter Beitrag vom 30. Mär 2005
 
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#13

Re: neue Komponente : "TlabeledLabel"

  Alt 29. Mär 2005, 18:56
und hier ist das schmuckstück (sollte selbsterklärend sein):
Delphi-Quellcode:
  TLabelLabel = class(TGraphicControl)
  private
    fAlignment: TAlignment;
    fCaption: String;
    fLeftMargin: Integer;
    fText: String;
    procedure FSetAlignment(AValue: TAlignment);
    procedure FSetStr(AType: Integer; AValue: String);
  public
    constructor Create(AOwner: TComponent); override;
    procedure Paint; override;
  published
    property Alignment: TAlignment read fAlignment write FSetAlignment default taLeftJustify;
    property Caption: String Index 0 read fCaption write FSetStr;
    property Font;
    property Text: String Index 1 read fText write FSetStr;
  end;

[...]

constructor TLabelLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  fAlignment := taLeftJustify;
  fCaption := 'Caption:';
  fLeftMargin := 5;
  fText := 'Text';
end;

procedure TLabelLabel.Paint;
var LCaptionWidth, LTextWidth, LLeft: Integer;
begin
  Canvas.Brush.Style := bsClear;
  Canvas.Font.Assign(Font);
  LCaptionWidth := Canvas.TextWidth(fCaption);
  LTextWidth := Canvas.TextWidth(fText);
  Canvas.TextOut(0, 0, fCaption);
  if (fAlignment = taLeftJustify) or
     (Width < LCaptionWidth + fLeftMargin + LTextWidth) then
    Canvas.TextOut(LCaptionWidth + fLeftMargin, 0, fText)
  else begin
    if fAlignment = taRightJustify then
      Canvas.TextOut(Width - LTextWidth, 0, fText)
    else begin
      LLeft := (Width - LCaptionWidth - fLeftMargin - LTextWidth) div 2;
      Canvas.TextOut(LCaptionWidth + fLeftMargin + LLeft, 0, fText);
    end;
  end;
end;

procedure TLabelLabel.FSetAlignment(AValue: TAlignment);
begin
  if AValue <> fAlignment then
  begin
    fAlignment := AValue;
    Repaint;
  end;
end;

procedure TLabelLabel.FSetStr(AType: Integer; AValue: String);
  procedure LSetVal(var LStr: String);
  begin
    if AValue <> LStr then
    begin
      LStr := AValue;
      Repaint;
    end;
  end;
begin
  if AType = 0 then
    LSetVal(fCaption)
  else if AType = 1 then
    LSetVal(fText);
end;
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz