怎样给Panel控件加上背景?(50分)

  • 主题发起人 主题发起人 说说
  • 开始时间 开始时间
unit TilePanel;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;

type
TTilePanel = class(TPanel)
private
FTile: TPicture;
procedure TileChanged(Sender: TObject);
procedure SetTile(Value: TPicture);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Tile: TPicture read FTile write SetTile;
end;

procedure Register;

implementation

constructor TTilePanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

FTile := TPicture.Create;
FTile.OnChange := TileChanged;
end;

destructor TTilePanel.Destroy;
begin
FTile.Free;

inherited Destroy;
end;

procedure TTilePanel.TileChanged(Sender: TObject);
begin
Invalidate;
end;

procedure TTilePanel.SetTile(Value: TPicture);
begin
FTile.Assign(Value);
end;

procedure TTilePanel.Paint;
var
x, y: Integer;
begin
inherited Paint;

if (FTile.Graphic <> nil) and (FTile.Width > 0) and (FTile.Height > 0) then
begin
y := 0;
while y < Height do
begin
x := 0;
while x < Width do
begin
Canvas.Draw(x, y, FTile.Graphic);
Inc (x, FTile.Width);
end;
Inc (y, FTile.Height);
end;
end;
end;

procedure Register;
begin
RegisterComponents('Croco', [TTilePanel]);
end;

end.
 
???
我给一个简单点的,你根据自己需要改一下吧

var CDC:HDC;
a:TCanvas;
bit:TBitmap;
begin
CDC:=getdc(Panel1.Handle);
a:=TCanvas.Create;
bit:=TBitmap.Create;
bit.LoadFromFile('c:/windows/tiles.bmp');
a.Handle:=cdc;
a.Draw(0,0,bit);
end;
 
用 TCanvas 的特性 StretchDraw or API -- BitBlt
 
在Panel上加个图片控件.
 
不要怪别人不理你,看看你自己能记住自己的帐号么??
说说,shuoshuo,sh1,sh2……,sh8,sh9……
该结束的题自己结束吧!!!!!!
 
后退
顶部