Dessin de polygones

De RAD Studio
Aller à : navigation, rechercher

Remonter à Dessin de formes


Pour dessiner, sur un canevas, un polygone ayant un nombre quelconque de côtés, appelez la méthode Polygon du canevas.

Polygon prend un tableau de points comme seul paramètre et relie les points avec le crayon, puis relie le dernier point au premier de façon à fermer le polygone. Après avoir dessiné les lignes, Polygon utilise le pinceau pour remplir la zone interne au polygone.

Par exemple, le code suivant dessine un triangle rectangle dans la moitié inférieure gauche de la fiche :

Delphi
procedure TForm1.FormPaint(Sender: TObject);
var 
  vertices: array[0..2] of TPoint;
begin
  vertices[0] := Point(10, 10);
  vertices[1] := Point(10, ClientHeight - 10);
  vertices[2] := Point(ClientWidth - 10, ClientHeight - 10);
  Canvas.Polygon(vertices);
end
C++
void __fastcall TForm1::FormPaint(TObject *Sender) {
    TPoint vertices[3];
    vertices[0] = Point(10, 10);
    vertices[1] = Point(10, ClientHeight - 10);
    vertices[2] = Point(ClientWidth - 10, ClientHeight - 10);
    Canvas->Polygon(vertices, 2);
}

Voir aussi