Author: Misha Moellner
How can I make a transparent or solid round form, without caption and border?
Answer:
This is a complete example of how to make a round form. Do not forget to create a
TButton to close the window
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls,
7 Forms, Dialogs, ExtCtrls, Buttons, StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 Button1: TButton;
12 procedure FormCreate(Sender: TObject);
13 procedure Button1Click(Sender: TObject);
14 private
15 { Private-Deklarationen}
16 procedure CreateParams(var Params: TCreateParams); override;
17 public
18 { Public-Deklarationen}
19 end;
20
21 var
22 Form1: TForm1;
23
24 implementation
25
26 {$R *.DFM}
27
28 { TForm1 }
29
30 procedure TForm1.CreateParams(var Params: TCreateParams);
31 begin
32 inherited CreateParams(Params);
33
34 {Remove caption and border}
35 Params.Style := Params.Style or ws_popup xor ws_dlgframe;
36 end;
37
38 procedure TForm1.FormCreate(Sender: TObject);
39 var
40 FormRgn: hRgn;
41 begin
42 {clear form}
43 Form1.Brush.Style := bsSolid; //bsclear;
44 {make form round}
45 GetWindowRgn(Form1.Handle, FormRgn);
46
47 { delete the old object }
48 DeleteObject(FormRgn);
49 { make the form rectangular }
50 Form1.Height := 500;
51 Form1.Width := Form1.Height;
52 { create the round form }
53 FormRgn := CreateRoundRectRgn(1, 1, Form1.Width - 1,
54 Form1.height - 1, Form1.width, Form1.height);
55
56 { set the new round window }
57 SetWindowRgn(Form1.Handle, FormRgn, TRUE);
58 end;
59
60 procedure TForm1.Button1Click(Sender: TObject);
61 begin
62 Form1.close;
63 end;
64
65 end.
|