Mega Code Archive

 
Categories / Delphi / Examples
 

Transparent form

Set the Forms BorderStyle to bsNone and BorderIcons.biSystemMenu to false. Put a Button on the Form. Then try this code out. Amazing! unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); var FullRgn, ClientRgn, ButtonRgn: THandle; Margin, X, Y: Integer; begin Margin := (Width - ClientWidth) div 2; FullRgn := CreateRectRgn(0, 0, Width, Height); X := Margin; Y := Height - ClientHeight - Margin; ClientRgn := CreateRectRgn (X, Y, X + ClientWidth, Y + ClientHeight); CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF); X := X + Button1.Left; Y := Y + Button1.Top; ButtonRgn := CreateRectRgn (X, Y, X + Button1.Width, Y + Button1.Height); CombineRgn(FullRgn, FullRgn, ButtonRgn, RGN_OR); SetWindowRgn(Handle, FullRgn, True); end; end.