我创建了一个从 TcustomControl 派生的 TSkinPanel
它有一个 FGraphic: TPicture。
FGraphic 绘制在 TSkinPanel 的画布上,如果您从 TObject Inspector 加载和图像,则可以正常工作。
但我不会在运行时加载图像“Form1.SkinPanel1.Picture.LoadFromFile('skin.bmp');
我创建了一个从 TcustomControl 派生的 TSkinPanel
它有一个 FGraphic: TPicture。
FGraphic 绘制在 TSkinPanel 的画布上,如果您从 TObject Inspector 加载和图像,则可以正常工作。
但我不会在运行时加载图像“Form1.SkinPanel1.Picture.LoadFromFile('skin.bmp');
如果您在调用时没有收到错误,Picture.LoadFromFile
那么它很可能正常工作,但您的控件根本没有对更改做出反应。首先要做的是处理Picture.OnChange
事件处理程序并执行一些操作:如果您自己进行绘画Invalidate()
,Assign()
只需调用
您必须使用该TPicture.OnChange
事件,例如:
type
TSkinPanel = class(TCustomControl)
private
FPicture: TPicture;
procedure PictureChanged(Sender: TObject);
procedure SetPicture(Value: TPicture);
protected
procedure Paint; override;
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
property Picture: TPicture read FPicture write SetPicture;
end;
constructor TSkinPanel.Create(Owner: TComponent);
begin
inherited;
FPicture := TPicture.Create;
FPicture.OnChange := PictureChanged;
end;
destructor TSkinPanel.Destroy;
begin
FPicture.Free;
inherited;
end;
procedure TSkinPanel.PictureChanged(Sender: TObject);
begin
Invalidate;
end;
procedure TSkinPanel.SetPicture(Value: TPicture);
begin
FPicture.Assign(Value);
end;
procedure TSkinPanel.Paint;
begin
if (FPicture.Graphic <> nil) and (not FPicture.Graphic.Empty) then
begin
// use FPicture as needed...
end;
end;