How to create a Pentagonal Shaped Form on Delphi?

Viewed 118

I´m trying to create a pentagonal shaped form in Delphi, but I can´t get the points drawed on the correct order, so the form keeps getting misshaped.

procedure TfrmPoligono.FormCreate(Sender: TObject);
var
  _Region: hRgn;

  _Tip,
  _MostLeft,
  _MostRight,
  _BottomLeft,
  _BottomRight: TPoint;
begin
  // fRegionPoints: array[0..4] of TPoint declared on the private section

  _Tip.X := 600;
  _Tip.Y := 0;

  _MostLeft.X := 100;
  _MostLeft.Y := 0;

  _MostRight.X := 1100;
  _MostRight.Y := 300;

  _BottomLeft.X := 200;
  _BottomLeft.Y := 700;

  _BottomRight.X := 1000;
  _BottomRight.Y := 700;

  fRegionPoints[0] := _Tip;
  fRegionPoints[1] := _MostLeft;
  fRegionPoints[2] := _MostRight;
  fRegionPoints[3] := _BottomLeft;
  fRegionPoints[4] := _BottomRight;

  _Region := CreatePolygonRgn(fRegionPoints[0], Length(fRegionPoints), ALTERNATE);

  SetWindowRgn(Handle, _Region, True);
end;

As you can see, I added the TPoints in the logical order that should be, top to bottom, left to rigth. Bu I tryed other configurations without success.

What am I doing wrong?

1 Answers

When you specify a polygonal shape in a computer, you specify the vertices in the same order you would use to draw the polygon on paper using a pencil: either clockwise or anticlockwise. In your case, choosing the anticlockwise orientation,

fRegionPoints[0] := _Tip;
fRegionPoints[1] := _MostLeft;
fRegionPoints[2] := _BottomLeft;
fRegionPoints[3] := _BottomRight;
fRegionPoints[4] := _MostRight;
Related