求助:控件消失了?(200分)

  • 主题发起人 主题发起人 hwave
  • 开始时间 开始时间
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.
 
我这里试过,根本就放不上去,出错
 
帮你顶顶
 
是不是此时lable还没创建
学习
 
》》》 inherited Create(AOwner);
》》》 caption:=AComponent.ClassName; //
》》》 TLabel(AComponent).Color:=Color; //

你的代码是危险的,不知道你用以上的代码的意思
 
不懂,帮顶
 
constructor TSetGDColor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Height := 25;
width := 80;
//Visible:=false;
end;
好象没有指定parent,系统怎样知道你要放在什么地方?
 
b2:=Tbutton.Create (self);
b2.Parent :=self;
with b2 do
begin
left:= 140;
Top:=90;
Width:=100;
Height:=50;
Font.Size:=13;
Caption:='AAA';
end;
b2.OnClick := b2onclick;
 

Similar threads

I
回复
0
查看
772
import
I
I
回复
0
查看
549
import
I
I
回复
0
查看
752
import
I
I
回复
0
查看
646
import
I
后退
顶部