Transparent Backgrouns

I have written an activeX form, however I want the background to be transparent.

I have no idea how to do this.

In addition, I want to make the TPanel component have a transparent background as well.

i.e. I want both of these control to NOT paint the background. How can I do this.

gavindewAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mhervaisCommented:
maybe you can catch the paint method (activated by the wmpaint message)

look in the vcl source how these component paint their background,

derive a component from each of them that overrides the paint method, and that does nothing in place of painting the bachground...

I would try like that
0
intheCommented:
well you can try this:


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
Procedure DoVisible;
procedure DoInvisible;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  FullRgn, ClientRgn, CtlRgn : THandle;
implementation

uses Unit10;

{$R *.DFM}
 procedure TForm1.DoInvisible;
      var
        AControl : TControl;
        A, Margin, X, Y, CtlX, CtlY : Integer;
       begin
        Margin := ( Width - ClientWidth ) div 2;
        //First, get form region
        FullRgn := CreateRectRgn(0, 0, Width, Height);
        //Find client area region
        X := Margin;
        Y := Height - ClientHeight - Margin;
        ClientRgn := CreateRectRgn( X, Y, X + ClientWidth, Y + ClientHeight );
        //'Mask' out all but non-client areas
        CombineRgn( FullRgn, FullRgn, ClientRgn, RGN_DIFF );
         //Now, walk through all the controls on the form and 'OR' them
        // into the existing Full region.
        for A := 0 to ControlCount - 1 do begin
          AControl := Controls[A];
          if ( AControl is TWinControl ) or ( AControl is TGraphicControl )
          then with AControl do begin
             if Visible then begin
              CtlX := X + Left;
              CtlY := Y + Top;
              CtlRgn := CreateRectRgn( CtlX, CtlY, CtlX + Width, CtlY + Height );
              CombineRgn( FullRgn, FullRgn, CtlRgn, RGN_OR );
             end;
           end;
        end;
        //When the region is all ready, put it into effect:
        SetWindowRgn(Handle, FullRgn, TRUE);
      end;

procedure TForm9.DoVisible;
      begin
        //To restore complete visibility:
        FullRgn := CreateRectRgn(0, 0, Width, Height);
        CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);
        SetWindowRgn(Handle, FullRgn, TRUE);
      end;

procedure TForm1.FormCreate(Sender: TObject);
begin
DoInvisible;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 DoVisible;
end;

end.

it make a form transparent(cheers to bryan7)but sorry dont know about the panel part.never seen a transparent panel before.
Regards Barry
0
yk030299Commented:
listen
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ITugayCommented:
listening....
0
JaymolCommented:
Hi.  I've written a component called TBorderForm that applies a Panel like look to a form, without drawing on the background (just the edges to give the bevelled look!)

See if that helps....

   http://SecretDelphi.cjb.net

Have a look on the components page.

Ta,

John.

PS. The source IS included, so you can see what I've done (Dead easy really!)
0
gandalf_the_whiteCommented:
listening...
0
X_KaliburCommented:
Howdy, y'all

Gav:

i know exactly what your looking for! What you do is send the window the WM_ERASEBKGND message, in order to erase the background...

I've done this for one of my applications, but i cant remember it off hand..

I dont guarantee hat this code works, but try it out....when i get access to my source code, i'll paste a full example...

type Form1 = object(TForm1)
         Private
         ....etc
         ....etc
         ....etc
         procedure MyMessage(msg : TMessage): message WM_ERASEBKGND



procedure TForm1.MyMessage(msg : TMessage)
begin
  msg.send;
end;




that should work....no guarantees, just yet....

i'll send the full code later
0
rwilson032697Commented:
listening
0
MaratXCommented:
Just do it

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Brush.Style := bsClear;
  Form1.BorderStyle := bsNone;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
intheCommented:
and the panel ...
0
X_KaliburCommented:
Howdy y'all,

Sorry i took so long, but school has started again, and cause this is my final year, i'm putting all my effort into school work..


unit Example;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormDblClick(Sender: TObject);
  private
    procedure MyMsg(var msg : TMessage); message WM_ERASEBKGND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MyMsg(var msg : TMessage);
begin
  msg.Result := 1;
end;
 
procedure TForm1.FormDblClick(Sender: TObject);
begin
  Form1.Close;
end;

end.


That snippet of code will allow the form to be transparent...


as for the Panel, well thats intersting...i couldnt immediately see a way around it....

-x
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.