unit Panel1;
interface
uses
SysUtils, Classes, StdCtrls, Controls, ExtCtrls, Graphics, Dialogs, Messages;
type
dgTPanel = class(TPanel)
private
FMyTopLabel: TLabel;
FMyTest: Boolean;
protected
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
public
published
property MyTopLabel: TLabel read FMyTopLabel write FMyTopLabel;
property MyTest: Boolean read FMyTest write FMyTest;
end;
// Neue Unterklasse FTopLabel1
FTopLabel = class(TLabel)
private
FMyBorder: Boolean;
protected
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Paint; override;
procedure DefineProperties();
procedure SetMyName(NewName: TComponentName);
function GetMyBorder: Boolean;
procedure SetMyBorder(Value: Boolean);
public
published
property MyBorder: Boolean read GetMyBorder write SetMyBorder;
end;
// Ende neue Unterklasse FTopLabel
// Komponente registrieren //
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Detlef', [dgTPanel]);
end;
// ----------------------- //
constructor dgTPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyTopLabel := FTopLabel.Create(self);
FMyTopLabel.SetSubComponent(True);
FMyTopLabel.Parent := self;
Height:= 150;
Width := 150;
Caption := '';
ShowCaption := False;
Refresh;
end;
destructor dgTPanel.Destroy;
begin
inherited;
end;
procedure dgTPanel.Paint;
begin
inherited;
if Width < 100 then Width := 100;
if Height < 100 then Height := 100;
ShowCaption := False;
end;
{ FTopLabel }
constructor FTopLabel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetMyName('TopLabel');
self.Caption := self.Name;
end;
destructor FTopLabel.Destroy;
begin
inherited;
end;
function FTopLabel.GetMyBorder: Boolean;
begin
Result := FMyBorder;
end;
procedure FTopLabel.SetMyBorder(Value: Boolean);
begin
if FMyBorder <> Value then
begin
FMyBorder := Value;
Repaint;
end;
end;
procedure FTopLabel.DefineProperties;
begin
AutoSize := False;
Left := 3;
Top := 3;
Width := self.Parent.Width - 6;
Transparent := False;
Alignment := taCenter;
Layout := tlCenter;
Font.Height := 5 - Height;
end;
procedure FTopLabel.Paint;
begin
inherited;
DefineProperties;
if self.MyBorder = True then
begin
Canvas.Pen.Color := clBlack;
end
else
begin
Canvas.Pen.Color := self.Color;
end;
Canvas.Rectangle(Left - 3, Top - 3, Width, Height);
end;
procedure FTopLabel.SetMyName(NewName: TComponentName);
begin
if NewName <> self.Name then
begin
if IsValidIdent(NewName)=True then
begin
self.SetName(NewName);
Update;
end;
end;
end;
end.