临时写的, 应该能工作.
type
TransparentPanel = class(TPanel)
private
FTransparent: Boolean;
procedure SetTransparent(value: Boolean);
procedure WMEraseBkgnd(var Msg: TMessage); message WM_ERASEBKGND;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure SetParent(AParent: TWinControl); override;
public
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
published
property Transparent: Boolean read FTransparent write SetTransparent;
end;
implimentation
procedure TTransparentPanel.SetTransparent(value: boolean);
begin
if ftransparent <> value then
begin
ftransparent := value;
invalidate;
end;
end;
procedure TTransparentPanel.WMEraseBkgnd(var Msg: TMessage);
begin
if ftransparent then msg.result := 1
else inherited;
end;
procedure TTransparentPanel.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
params.exstyle := params.exstyle or WS_EX_TRANSPARENT;
end;
procedure TTransparentPanel.SetParent(AParent: TWinControl);
begin
inherited setparent(aparent);
if (aparent <> nil) and aparent.HandleAllocated
and (GetWindowLong(aparent.handle, GWL_STYLE) and WS_CLIPCHILDREN <> 0) then
setwindowlong(aparent.handle, GWL_STYLE,
GetWindowLong(aparent.handle, GWL_STYLE)
and not WS_CLIPCHILDREN);
end;
procedure TTransparentPanel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
invalidate;
inherited setbounds(aleft, atop, awidth, aheight);
end;
end.