在delphi2005中,如何实现panel面板具有透明效果? ( 积分: 100 )

  • 主题发起人 主题发起人 ldhlyh
  • 开始时间 开始时间
L

ldhlyh

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi2005中,如何实现panel面板具有透明效果?
 
在delphi2005中,如何实现panel面板具有透明效果?
 
看样子问题很难呀!如果有那位高手解决,再加100分。
 
给你写一个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;
 
后退
顶部