Einzelnen Beitrag anzeigen

Benutzerbild von Tonic1024
Tonic1024

Registriert seit: 10. Sep 2003
Ort: Cuxhaven
559 Beiträge
 
RAD-Studio 2009 Ent
 
#3

Re: Komponente zur Designzeit die Zweite

  Alt 4. Dez 2003, 16:10
Moin...

Ich glaube so habe ich noch nie mit einem Problem gekämpft...

Sei mir nicht böse, ich poste mal alles...

Das stellt meinen letzten Stand dar... ist schon zig mal wieder umgeworfen und neu gemacht...
Derzeitiges Problem: Komponente wird erzeugt, liegt mit allen Werten (die auch korrekt sind) auf dem Form und wenn die App startet ist nicht das shape sondern der Button zu sehen. Ich dachte, wenn ich den Konstruktor überschreibe, dann erscheint nicht mehr der Button?!?

Delphi-Quellcode:
type
  TBluBtn = class(TButton)
    procedure AnimationTimer(Sender: TObject);
  private
    Form: TForm;
    Panel: TPanel;
    FColor: TColor;
    FCaption: String;
    FOnClick: TNotifyEvent;
    procedure SetColor(const Value: TColor);
    procedure SetCaption(const Value: String);
    procedure DoOnClick(Sender: TObject);
  protected
  public
  published
    constructor Create(AOwner: TComponent);override;
    property HighlightedColor: TColor read FColor write SetColor;
    property Caption: String read FCaption write SetCaption;
    property onClick: TNotifyEvent read FOnClick write FOnClick;
  end;

procedure Register;

var shape: TShape;
    Lbl: TLabel;
    timer: TTimer;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TBluBtn]);
end;

procedure TBluBtn.DoOnClick(Sender: TObject);
begin
  If Assigned(FOnClick) Then
    FOnClick(Self);
end;

constructor TBluBtn.Create(AOwner: TComponent);
begin
  inherited create(AOwner);
  FCaption:='BlueButton';
  Self.Form:=Form;
  Self.Panel:=Panel;

  Self.FColor:=clSkyblue;

  shape:=TShape.Create(Self);
  shape.Shape:=stRoundRect;
  shape.Height:=20;
  shape.Brush.Color:=Self.FColor;
  shape.Pen.Color:=ColorAdjustLuma(Self.FColor,-70,false);

  Lbl:=TLabel.Create(Self);
  Lbl.AutoSize:=true;
  Lbl.Transparent:=true;
  Lbl.Font.Color:=clGray;
  Lbl.Caption:=FCaption;
  LbL.OnClick:=DoOnClick;

  timer:=TTimer.Create(Self);
  timer.Interval:=1;
  timer.OnTimer:=AnimationTimer;
  timer.Enabled:=true;

  shape.Parent:=(AOwner as TForm);
  Lbl.Parent:=(AOwner as TForm);
  Form:=(AOwner as TForm);
  Panel:=nil;

end;


procedure TBluBtn.SetCaption(const Value: String);
begin
  FCaption:=Value;
end;

procedure TBluBtn.AnimationTimer(Sender: TObject);
var pt: TPoint;
    ThisPanel: TPanel;
begin
  ThisPanel:=TPanel.Create(self);
  ThisPanel.Top:=0;
  ThisPanel.Left:=0;

  if Panel <> nil then
    ThisPanel:=Panel;

  GetCursorPos(pt);
  if (pt.X > Form.Left+ThisPanel.Left+shape.Left+4) AND
      (pt.X < Form.Left+ThisPanel.Left+shape.Left+shape.Width+4) AND
      (pt.Y > Form.Top+ThisPanel.Top+shape.Top+23) AND
      (pt.Y < Form.Top+ThisPanel.Top+shape.Top+shape.Height+23) then
  begin
    shape.Visible:=true;
    Lbl.Font.Color:=clBlack;
  end
  else
  begin
    shape.Visible:=false;
    Lbl.Font.Color:=clGray;
  end;
  
  //Weil Left sonst nicht das Objekt neu zeichnet... ist zugegebenermaßen ein bissel unschön
  shape.Brush.Color:=FColor;
  shape.Pen.Color:=ColorAdjustLuma(Self.FColor,-70,false);
  shape.Left:=Self.Left;
  shape.Top:=Self.Top;
  shape.Width:=Lbl.Width+20;
  Lbl.Top:=Shape.Top+3;
  Lbl.Left:=Shape.Left+9;
  Lbl.Caption:=FCaption;
end;

procedure TBluBtn.SetColor(const Value: TColor);
begin
  FColor:=Value;
end;
*säuftz*
Der frühe Vogel fängt den Wurm, richtig.
Aber wird nicht auch der frühe Wurm vom Vogel gefressen?
  Mit Zitat antworten Zitat