Solved

Transparent Form

Posted on 1998-10-19
14
139 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now