我正在尝试在 Delphi 中创建一个五边形的形状,但是我无法按正确的顺序绘制点,因此该形状不断变形。
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;
Run Code Online (Sandbox Code Playgroud)
如您所见,我按照从上到下、从左到右的逻辑顺序添加了 TPoint。但是我尝试了其他配置没有成功。
我究竟做错了什么?
在计算机中指定多边形时,指定顶点的顺序与使用铅笔在纸上绘制多边形的顺序相同:顺时针或逆时针。在您的情况下,选择逆时针方向,
fRegionPoints[0] := _Tip;
fRegionPoints[1] := _MostLeft;
fRegionPoints[2] := _BottomLeft;
fRegionPoints[3] := _BottomRight;
fRegionPoints[4] := _MostRight;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
109 次 |
| 最近记录: |