Thema: Delphi eigene Klasse Button

Einzelnen Beitrag anzeigen

Phiennes

Registriert seit: 30. Nov 2008
Ort: Bochum
30 Beiträge
 
#4

Re: eigene Klasse Button

  Alt 19. Mai 2009, 23:45
Hmm irgendwie komme ich doch nicht weiter^^.

Das Label wird einfach nicht angezeigt.

Delphi-Quellcode:
unit bkButton;

interface

uses
  SysUtils, Classes, Controls, Graphics, StdCtrls;

type
  TbkButton = class(TCustomControl)
  private
    { Private-Deklarationen }
    Pressed: byte;
    BLabel: TLabel;
  protected
    { Protected-Deklarationen }
    procedure Paint; override;
  public
    { Public-Deklarationen }
    constructor Create(AOwner: TComponent); Override;
  published
    { Published-Deklarationen }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('bkModule', [TbkButton]);
end;

constructor TbkButton.Create(AOwner: TComponent);
VAR xw,yw:Integer;
begin
  xw:=200;
  yw:=22;
  inherited Create (AOwner);
  Pressed:=0;
  SetBounds(0,0,xw,yw);

  BLabel:= TLabel.Create(self);
  BLabel.Caption:='bkButtonX';
end;

procedure TbkButton.Paint;
begin
  canvas.brush.color:=clred;
  canvas.Rectangle(0,0,width,height);
  
  BLabel.Left:=2;
  BLabel.Width:=width-4;
  BLabel.Top:=round(height/2)-6;
  BLabel.Height:=13;
  BLabel.Alignment:=taCenter;
  BLabel.Transparent:=false;
  BLabel.Visible:=true;
  BLabel.Color:=clGreen;
  BLabel.Enabled:=true;
end;

end.
habs rausgefunden es fehlte:
 BLabel.parent:= self;
  Mit Zitat antworten Zitat