本控件继承自Delphi自带的TShape,构造函数:
constructor TMyShape.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
height := 15;
Canvas.TextOut(0,0, IntToStr(Percent)+'%');
end;
编译通过,但是新建一个项目,并将控件拖到窗体上时错误提示框:Control '' has no parent window!
TShape的父类TGraphicControl中不是有Canvas,为什么我在本控件中使用Canvas会有错?
constructor TMyShape.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
height := 15;
Canvas.TextOut(0,0, IntToStr(Percent)+'%');
end;
编译通过,但是新建一个项目,并将控件拖到窗体上时错误提示框:Control '' has no parent window!
TShape的父类TGraphicControl中不是有Canvas,为什么我在本控件中使用Canvas会有错?
如果这个Percent我在更改这个值之后要求控件马上能作出反应,应该怎么写?
begin
if Value <> fpercent then
begin
Fpercent := Value;
Invalidate;
end;
end;