?
Solved

Transparent Backgrouns

Posted on 2000-01-30
11
Medium Priority
?
241 Views
Last Modified: 2010-07-27
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.

0
Comment
Question by:gavindew
11 Comments
 
LVL 4

Expert Comment

by:mhervais
ID: 2447843
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
 
LVL 17

Expert Comment

by:inthe
ID: 2450183
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
 
LVL 1

Expert Comment

by:yk030299
ID: 2451162
listen
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 9

Expert Comment

by:ITugay
ID: 2456241
listening....
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2457743
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
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 2463025
listening...
0
 
LVL 1

Expert Comment

by:X_Kalibur
ID: 2476806
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2476813
listening
0
 

Accepted Solution

by:
MaratX earned 200 total points
ID: 2478043
Just do it

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

Expert Comment

by:inthe
ID: 2478290
and the panel ...
0
 
LVL 1

Expert Comment

by:X_Kalibur
ID: 2483860
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question