Author: Tomas Rutkauskas
How to create a polygon-shaped form using regions
Answer:
To start with, we need to make an array of points of all corners of the form (there
can be as many as you want). Next we use the Windows API call CreatePolygonRgn to
get a handle to the region we have just defined. Finally we need to set this region
the window we want to be that shape using another API call SetWindowRgn. To see
this in effect create a new project and in the forms onCreate event have:
1 procedure TForm1.FormCreate(Sender: TObject);
2 var
3 Region: HRgn;
4 Points: array[0..11] of TPoint;
5 begin
6 {Define the points of a W shape}
7 Points[0] := Point(0, 0);
8 Points[1] := Point(50, 0);
9 Points[2] := Point(180, 200);
10 Points[3] := Point(218, 100);
11 Points[4] := Point(256, 200);
12 Points[5] := Point(385, 0);
13 Points[6] := Point(435, 0);
14 Points[7] := Point(256, 300);
15 Points[8] := Point(218, 200);
16 Points[9] := Point(180, 300);
17 {Define the region}
18 Region := CreatePolygonRgn(Points, 10, ALTERNATE);
19 {Set the window to have the above defined region}
20 SetWindowRgn(Handle, Region, True);
21 end;
|