Author: Jonas Bilinkevicius
How to create a transparent form which is still moveable
Answer:
You can achieve a transparency effect by creating a window region that includes
only the controls on the form but not the background. Making a window transparent
and still moveable:
1 procedure TForm1.Button2Click(Sender: TObject);
2 var
3 frmRegion, tempRegion: HRGN;
4 i: Integer;
5 Arect: TRect;
6 begin
7 frmRegion := 0;
8 for I := 0 to ControlCount - 1 do
9 begin
10 { create a region for the control }
11 aRect := Controls[i].BoundsRect;
12 { coordinates have to be window-relative, not client area relative }
13 OffsetRect(aRect, clientorigin.x - left, clientorigin.y - top);
14 tempRegion := CreateRectRgnIndirect(aRect);
15 { merge the region with the "summary" region we are building }
16 if frmRegion = 0 then
17 frmRegion := tempRegion
18 else
19 begin
20 CombineRgn(frmRegion, frmRegion, tempRegion, RGN_OR);
21 DeleteObject(tempRegion);
22 end;
23 end;
24 { create a region for the caption and menu bar and add it to the summary }
25 tempregion := CreateRectRgn(0, 0, Width, GetSystemMetrics(SM_CYCAPTION) +
26 GetSystemMetrics(SM_CYSIZEFRAME) +
27 GetSystemMetrics(SM_CYMENU) * Ord(Menu < > nil));
28 CombineRgn(frmRegion, frmRegion, tempRegion, RGN_OR);
29 DeleteObject(tempRegion);
30 SetWindowRgn(handle, frmRegion, true);
31 end;
|