That had no effect. The panel still showed.
Main Topics
Browse All TopicsHow can I make a TPanel in Delphi 5 transparent? Or at least copy the area of the TForm behind the TPanel and paint it to the TPanel canvas? I need to be able to do this without using a third-party component.
Rich
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this, posted to the Borland Newsgroups by Josh Breitbach:
TSkinPanel = Class (TCustomPanel)
Private
Procedure WMEraseBkGnd (Var Msg : TWMEraseBkGnd); Message WM_ERASEBKGND;
Protected
Procedure Paint; Override;
Public
Constructor Create ( AOwner : TComponent); Override;
Destructor Destroy; Override;
End;
{-------------------------
Constructor TSkinPanel.Create ( AOwner : TComponent);
Begin
Inherited Create (AOwner);
Width := 100;
Height := 100;
End;
{-------------------------
Destructor TSkinPanel.Destroy;
Begin
Inherited Destroy;
End;
{-------------------------
Procedure TSkinPanel.Paint;
Var
TheClientRect : TRect;
SaveIndex : Integer;
Begin
{ This code will re-paint the parent panel }
{ This way, you may have 1 trans panel on another }
SaveIndex := SaveDC (Canvas.Handle);
MoveWindowOrg (Canvas.Handle, -Left, -Top);
Parent.Perform (WM_PAINT, Canvas.Handle, 0);
RestoreDC (Canvas.Handle, SaveIndex);
TheClientRect := ClientRect;
{ Do your drawing here }
End;
{-------------------------
Procedure TSkinPanel.WMEraseBkGnd (Var Msg : TWMEraseBkGnd);
Begin
Msg.Result := 0;
End;
{-------------------------
or this one by Serge Gubenko
TMyTransparentPanel = class(TPanel)
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure Paint; override;
end;
{...}
procedure TMyTransparentPanel.Create
begin
inherited CreateParams(Params);
if not (csDesigning in ComponentState)
then Params.ExStyle:=Params.ExS
end;
procedure TMyTransparentPanel.Paint;
var
XBitMap: TBitMap;
XOldDC: HDC;
XRect: TRect;
begin
{This panel will be transparent only in Run Time}
if (csDesigning in ComponentState)
then inherited Paint
else begin
XRect:=ClientRect;
XOldDC:=Canvas.Handle;
XBitMap:=TBitMap.Create;
try
XBitMap.Height:=Height; XBitMap.Width:=Width;
Canvas.Handle:=XBitMap.Can
inherited Paint;
RedrawWindow(Parent.Handle
RDW_ERASE or RDW_INVALIDATE or
RDW_NOCHILDREN or RDW_UPDATENOW);
finally
Canvas.Handle:=XOldDC;
Canvas.BrushCopy(XRect, XBitMap, XRect, Color);
XBitMap.Free;
end;
end;
end;
or this one by Peter Below:
unit TransparentPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
ExtCtrls;
type
TTransparentPanel = class(TPanel)
private
{ Private declarations }
FBackground: TBitmap;
Procedure WMEraseBkGnd( Var msg: TWMEraseBkGnd );
message WM_ERASEBKGND;
protected
{ Protected declarations }
Procedure CaptureBackground;
Procedure Paint; override;
public
{ Public declarations }
Procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
property Canvas;
Constructor Create( aOwner: TComponent ); override;
Destructor Destroy; override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('PBGood
end;
{ TTransparentPanel }
procedure TTransparentPanel.CaptureB
var
canvas: TCanvas;
dc: HDC;
sourcerect: TRect;
begin
FBackground := TBitmap.Create;
with Fbackground do begin
width := clientwidth;
height := clientheight;
end; { with }
sourcerect.TopLeft := ClientToScreen(clientrect.
sourcerect.BottomRight := ClientToScreen( clientrect.BottomRight );
dc:= CreateDC( 'DISPLAY', nil, nil, nil );
try
canvas:= TCanvas.Create;
try
canvas.handle:= dc;
Fbackground.Canvas.CopyRec
finally
canvas.handle := 0;
canvas.free;
end; { finally }
finally
DeleteDC( dc );
end; { finally }
end;
constructor TTransparentPanel.Create(a
begin
inherited;
ControlStyle := controlStyle - [csSetCaption];
end;
destructor TTransparentPanel.Destroy;
begin
FBackground.free;
inherited;
end;
procedure TTransparentPanel.Paint;
begin
if csDesigning In ComponentState Then
inherited
// would need to draw frame and optional caption here
// do NOT call inherited, the control fills its client area if you do!
end;
procedure TTransparentPanel.SetBound
AHeight: Integer);
begin
if Visible and HandleAllocated and not (csDesigning In
ComponentState) then begin
Fbackground.Free;
Fbackground := Nil;
Hide;
inherited;
Parent.Update;
Show;
end
else
inherited;
end;
procedure TTransparentPanel.WMEraseB
var
canvas: TCanvas;
begin
if csDesigning In ComponentState Then
inherited
else begin
if not Assigned( FBackground ) then
Capturebackground;
canvas := TCanvas.create;
try
canvas.handle := msg.DC;
canvas.draw( 0, 0, FBackground );
finally
canvas.handle := 0;
canvas.free;
end; { finally }
msg.result := 1;
end;
end;
end.
Business Accounts
Answer for Membership
by: sftwengPosted on 2004-04-12 at 02:50:39ID: 10804287
Try this:
e, GWL_EXSTYLE, WS_EX_TRANSPARENT);
Panel1.Brush.Style := bsClear;
SetWindowLong(Panel1.Handl