为什么继承自TGRAPHICCONTROL的控件不能画自己呢?为什么说‘’IS NOT A CONTROL?(17分)

  • 主题发起人 主题发起人 TIGER@DELPHI
  • 开始时间 开始时间
T

TIGER@DELPHI

Unregistered / Unconfirmed
GUEST, unregistred user!
type
aaa = class(TgraphicControl)
private
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(aowner:tcomponent);override;
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

constructor aaa.create(aowner:tcomponent);
begin
inherited create(aowner);
canvas.MoveTo(left,Top);
canvas.LineTo(Left+Width,Top);
canvas.LineTo(Left+Width,Top+Height);
canvas.LineTo(Left,Top+Height);
canvas.LineTo(Left,Top);
end;
 
修改如下:
type
aaa = class(TgraphicControl)
private
{ Private declarations }
protected
procedure Paint;override;//注意,添加函数
public
constructor create(aowner:tcomponent);override;
{ Public declarations }
published
{ Published declarations }
end;

procedure Register;

implementation

constructor aaa.create(aowner:tcomponent);
begin
inherited create(aowner);
//其他初始化工作,在这里是空的,可以不Override
end;
procedure aaa.Paint;//在这里才能画
begin
canvas.MoveTo(left,Top);
canvas.LineTo(Left+Width,Top);
canvas.LineTo(Left+Width,Top+Height);
canvas.LineTo(Left,Top+Height);
canvas.LineTo(Left,Top);
end;
 
接受答案了.
 
后退
顶部