我最终想开发一个图形程序,现在想把各种基本图形做成控件
为了能在控件的运行期模拟设计期的效果,学习网上的例子,从Twincontrol继承
我下面写的出错:“canvas does not allow drawing”
为什么?怎么办呢?
unit myfirst1;interfaceuses
SysUtils, Classes, Controls,Graphics;type
tmyfirst1 = class(TWinControl)
private
Fcanvas:Tcanvas;
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(Aowner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
{ Published declarations }
end;procedure Register;implementation
constructor Tmyfirst1.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
Fcanvas:=Tcanvas.Create;
fcanvas.Lock;
fcanvas.Rectangle(30,30,80,60);
fcanvas.Unlock;end;
destructor Tmyfirst1.destroy;
begin
inherited destroy;
fcanvas.Free;
end;
procedure Register;
begin
RegisterComponents('user', [tmyfirst1]);
end;end.
为了能在控件的运行期模拟设计期的效果,学习网上的例子,从Twincontrol继承
我下面写的出错:“canvas does not allow drawing”
为什么?怎么办呢?
unit myfirst1;interfaceuses
SysUtils, Classes, Controls,Graphics;type
tmyfirst1 = class(TWinControl)
private
Fcanvas:Tcanvas;
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(Aowner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
{ Published declarations }
end;procedure Register;implementation
constructor Tmyfirst1.create(Aowner:Tcomponent);
begin
inherited create(Aowner);
Fcanvas:=Tcanvas.Create;
fcanvas.Lock;
fcanvas.Rectangle(30,30,80,60);
fcanvas.Unlock;end;
destructor Tmyfirst1.destroy;
begin
inherited destroy;
fcanvas.Free;
end;
procedure Register;
begin
RegisterComponents('user', [tmyfirst1]);
end;end.
fcanvas.pen.color没用