RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCanvas.Polyline Method

Draws a series of lines on the canvas with the current pen, connecting each of the points passed to it in Points.

Pascal
procedure Polyline(const Points: array of TPoint);
C++
__fastcall Polyline(const array of TPoint Points);

Use Polyline to connect a set of points on the canvas. If you specify only two points, Polyline draws a single line.  

The Points parameter is an array of points to be connected.

Note: The Points_Size parameter is the index of the last point in the array (one less than the total number of points).
Note: In Delphi, you can use the Slice function to pass a portion of an array of points to the Polyline method. For example, to form a line connecting the first ten points from an array of 100 points, use the Slice function as follows:

Canvas.Polyline(Slice(PointArray, 10));

Calling the MoveTo function with the value of the first point, and then repeatedly calling LineTo with all subsequent points will draw the same image on the canvas. However, unlike LineTo, Polyline does not change the value of PenPos.  

C++ Examples: 

 

/*
This example paints a white five-pointed star in a paintbox 
control:
*/
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
  TPaintBox *pPB = (TPaintBox *)Sender;
  TPoint points[6];
  pPB->Canvas->Pen->Color = clWhite;
  points[0].x = 40;
  points[0].y = 10;
  points[1].x = 20;
  points[1].y = 60;
  points[2].x = 70;
  points[2].y = 30;
  points[3].x = 10;
  points[3].y = 30;
  points[4].x = 60;
  points[4].y = 60;
  points[5].x = 40;
  points[5].y = 10;
  pPB->Canvas->Polyline(points,5);
}

 

Delphi Examples: 

{
This example paints a white five-pointed star in a paintbox 
control:
} 
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  with Sender as TPaintBox do
  begin
    Canvas.Pen.Color := clWhite;
    Canvas.Polyline([Point(40, 10), Point(20, 60), Point(70, 30),
    Point(10, 30), Point(60, 60), Point(40, 10)]);
  end;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!