TcustomControl から派生した TSkinPanel を作成しました
FGraphic: TPicture があります。
FGraphic は TSkinPanel のキャンバスに描画され、TObject インスペクタから読み込んで画像化すると正常に動作します。
しかし、実行時に画像をロードすることはできません "Form1.SkinPanel1.Picture.LoadFromFile('skin.bmp');
TcustomControl から派生した TSkinPanel を作成しました
FGraphic: TPicture があります。
FGraphic は TSkinPanel のキャンバスに描画され、TObject インスペクタから読み込んで画像化すると正常に動作します。
しかし、実行時に画像をロードすることはできません "Form1.SkinPanel1.Picture.LoadFromFile('skin.bmp');
呼び出し時にエラーが発生しない場合は、正常にPicture.LoadFromFile
機能している可能性がありますが、コントロールが単に変更に反応していません。最初に行うことは、Picture.OnChange
イベント ハンドラーを処理して何かを行うことです。自分で描画を行う場合は、 を呼び出すだけです。Picture を使用Invalidate()
して描画を行う他のコントロールを設定している場合は、適切なAssign()
フォーム OnChange を実行します。
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;