unit Unit6;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.StdCtrls;
type
TPanel =
class(
Vcl.ExtCtrls.TPanel)
private
FBitmap: TBitmap;
procedure SetBitmap(
const Value: TBitmap);
protected
procedure Paint;
override;
public
property Bitmap: TBitmap
read FBitmap
write SetBitmap;
end;
TForm6 =
class(TForm)
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
FBitmap: TBitmap;
public
{ Public-Deklarationen }
end;
var
Form6: TForm6;
implementation
{$R *.dfm}
{ TPanel }
procedure TPanel.Paint;
begin
inherited;
if Assigned(FBitmap)
then
Canvas.Draw(0, 0, FBitmap);
end;
procedure TPanel.SetBitmap(
const Value: TBitmap);
begin
FBitmap := Value;
Invalidate;
end;
procedure TForm6.Button1Click(Sender: TObject);
begin
Panel1.Bitmap :=
nil;
end;
procedure TForm6.Button2Click(Sender: TObject);
begin
Panel1.Bitmap := FBitmap;
end;
procedure TForm6.FormCreate(Sender: TObject);
begin
FBitmap := TBitmap.Create;
FBitmap.Width := Panel1.Width;
FBitmap.Height := Panel1.Height;
FBitmap.Canvas.Brush.Color := clRed;
FBitmap.Canvas.FillRect(Rect(0, 0, FBitmap.Width, FBitmap.Height));
Panel1.Bitmap := FBitmap;
end;
procedure TForm6.FormDestroy(Sender: TObject);
begin
FBitmap.Free;
end;
end.