Solved

Transparent Form

Posted on 1998-10-19
14
143 Views
Last Modified: 2010-04-06
Does anyone know how to make a from Transparet?
I mean the in some areas of the form you see the Things under the form.
0
Comment
Question by:TheSwine
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1343382
procedure TForm1.FormCreate(Sender: TObject);
begin
  Brush.Style:=bsClear;
  BorderStyle:=bsNone;
end;

0
 
LVL 1

Author Comment

by:TheSwine
ID: 1343383
That's nice but, When I move the form he doesn't redraw,
(Leave border and move the form to see what I Mean)

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343384
Hi TheSwine,

I'm sure that from the explaination in this article you can get the thing you want.

http://www.delumpa.com/tips/forms/forms4.htm

and here is a component, which gives everything you want :

http://www.lawrenz.com/coolform/index.htm

Regards, Zif.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:bryan7
ID: 1343385
hey ! try this:

it works perfectly under Delphi 3:  ( and it redraws when u move it )

Drop a panel and 2 buttons to the form and use this:



unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    Button2: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
    procedure DoVisible;
    procedure DoInvisible;
  public
    { Public declarations }
  end;

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

implementation

{$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 TForm1.FormDestroy(Sender: TObject);
begin
  //Clean up the regions we created
  DeleteObject(ClientRgn);
  DeleteObject(FullRgn);
  DeleteObject(CtlRgn);
end;

procedure TForm1.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
  //We start out as a transparent form....
  DoInvisible;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //This button just toggles between transparent and not trans..
  if Button1.Caption = 'Show Form' then begin
    DoVisible;
    Button1.Caption := 'Hide Form';
  end
  else begin
    DoInvisible;
    Button1.Caption := 'Show Form';
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  //Need to address the transparency if the form gets re-sized.
  //Also, note that Form1 scroll bars are set to VISIBLE/FALSE.
  //I did that to save a little coding here....
  if Button1.Caption = 'Show Form' then
    DoInvisible
  else
    DoVisible;
end;

end.





ok, I hope it helps you,   see ya !

bryan.    ( I'm a new 'expert' from 19.10.98 )

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343386
Hey brayn, looks like the sample code of Harm. Nice.

TheSwine,

 do you want it like the code above ?

  -> Only form transparent, components not

 or Only piece of form transparent (like a hole?)

Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343387
anyhow, if somebody hasn't seen coolform... you just have to see it. I once wanted to make something like this myself, but then I found this, I was amazed, you can get everything done with it! From holes, to all different shapes... I never could have done it like they did. Marvellous piece of coding...
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343388
hehe, after seeing some examples, etc... I got this as result, have fun with it :

unit unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
 TempRgn, HoleRgn    : THandle;
begin
 IF Width > Height THEN Width := Height
  ELSE Height := Width;
 TempRgn := CreateRectRgn(0, 0, Width, Height);
 HoleRgn := CreateEllipticRgn((Width DIV 4), (Height DIV 4),3*(Width DIV 4), 3*(Height DIV 4));
 CombineRgn(TempRgn, TempRgn, HoleRgn, RGN_DIFF);
 SetWindowRgn(Handle, TempRgn, True);
 DeleteObject(HoleRgn);
 DeleteObject(TempRgn);
end;

end.

Regards, Zif.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1343389
Zifnab, yeah, the code is not mine, of course,

your last example. ... is great !

yeah, it is,


0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343390
Hey, hello bryan7, how is your second day at E-E? :-)

Well, it doesn't matter if the source isn't yours, if it helps somebody out, then it's great! Besides, by looking/searching for an answer you improve your experience as well. I think that's why we all love E-E.

The hole is funny isn't it... Improving the graphic in some way and we can make a nice recycle bin from it :-). ( Drop it in the hole babe! ) .... this is copyrighted by ZifNab ... hehe.

've a nice day.

Zif.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 1343391
hey Zifnab ,

yeah, I Love E-E too. And the code for the transparent form and components is great,
really.


See ya =)
bryan

0
 
LVL 1

Author Comment

by:TheSwine
ID: 1343392
ZifNab,Bryan7 Hi!
ZifNab: I must say that I've checked out coolform and It's nice , but it does not make the things under the transparent area to act normally ( If you click a transparent area inside the form region you simplly move the form ) I've also check your sample with the CreateEllipticRgn and I just can't understand what happend when I run the app
On the other hand the sample code bryan7 gave (the one with DoInvisible ) Is exactlly what I was looking for, so I believe he should gets the points, though basiclly I must say that you answered my question too ( I simply not defined my exect requirements in my question ) so what do you say ? who should I give the points to?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343393
Hi TheSwine, I don't mind if you give bryan the points. Zif.
0
 
LVL 1

Author Comment

by:TheSwine
ID: 1343394
Bryan7, Post anything as an answer to earn your points.

0
 
LVL 3

Accepted Solution

by:
bryan7 earned 200 total points
ID: 1343395
hey !

thanx !

these will be my first points.. wow... I never thought I would get 200 for my first answer.
thanx ya all.

glad to help,
bryan =)


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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