H
hwave
Unregistered / Unconfirmed
GUEST, unregistred user!
//编写这个控件,设置一个颜色,放到Form上,再放置TLabel控件时,所有的TLabel控件会按照该控件的颜色修改自己的颜色
unit SetGDColor;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, stdctrls;
type
TSetGDColor = class(TCustomPanel)
private
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
published
property caption;
property Color;
property Visible;
property Parent;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Test', [TSetGDColor]);
end;
{ TSetGDColor }
constructor TSetGDColor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height := 25;
width := 80;
//Visible:=false;
end;
procedure TSetGDColor.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent<>Self)and(Operation = opInsert)and (csdesigning in componentstate) then // and (csdesigning in componentstate)
begin
caption:=AComponent.ClassName; //
if (AComponent is TLabel) then
TLabel(AComponent).Color:=Color; //因为这一句,放置到Form的TLabel控件闪一下就消失了
end;
end;
end.
unit SetGDColor;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, stdctrls;
type
TSetGDColor = class(TCustomPanel)
private
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
published
property caption;
property Color;
property Visible;
property Parent;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Test', [TSetGDColor]);
end;
{ TSetGDColor }
constructor TSetGDColor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height := 25;
width := 80;
//Visible:=false;
end;
procedure TSetGDColor.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent<>Self)and(Operation = opInsert)and (csdesigning in componentstate) then // and (csdesigning in componentstate)
begin
caption:=AComponent.ClassName; //
if (AComponent is TLabel) then
TLabel(AComponent).Color:=Color; //因为这一句,放置到Form的TLabel控件闪一下就消失了
end;
end;
end.