给你写一个panel类:
delphi6中通过,我没有delphi2005
TTransPanel = class(TCustomControl)
private
FBitmap: TBitmap;
procedure SetBitmap(const Value: TBitmap);
procedure BitmapChange(Sender: TObject);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Bitmap: TBitmap read FBitmap write SetBitmap;
end;
procedure TTransPanel.paint;
begin
Canvas.Draw(0, 0, FBitmap);
end;
constructor TTransPanel.Create(AOwner: TComponent);
begin
inherited;
FBitmap := TBitmap.Create;
FBitmap.PixelFormat := pf24Bit;
FBitmap.Width := 0;
FBitmap.Height := 0;
FBitmap.OnChange := BitmapChange;
end;
destructor TTransPanel.Destroy;
begin
if Assigned(FBitmap) then FBitmap.Free;
inherited;
end;
procedure TTransPanel.SetBitmap(const Value: TBitmap);
begin
if Assigned(Value) then begin
Updating;
FBitmap.Width := Value.Width;
FBitmap.Height := Value.Height;
FBitmap.PixelFormat := pf24bit;
Updated;
FBitmap.Canvas.Draw(0, 0, Value);
end else FBitmap.Assign(nil);
end;
procedure TTransPanel.BitmapChange(Sender: TObject);
var
vRGN: HRGN;
begin
if csUpdating in ComponentState then Exit;
Width := FBitmap.Width;
Height := FBitmap.Height;
vRGN := GraphicToRGN(FBitmap, Point(0, 0));
try
SetWindowRgn(Handle, vRGN, True);
finally
DeleteObject(vRGN);
end;
Repaint;
end;