Drawing Polylines

From RAD Studio
Jump to: navigation, search

Go Up to Drawing Lines and Polylines


In addition to individual lines, the canvas can also draw polylines, which are groups of any number of connected line segments.

To draw a polyline on a canvas, call the Polyline method of the canvas.

The parameter passed to the Polyline method is an array of points. You can think of a polyline as performing a MoveTo on the first point and LineTo on each successive point. For drawing multiple lines, Polyline is faster than using the MoveTo method and the LineTo method because it eliminates a lot of call overhead.

The following method, for example, draws a rhombus in a form:

void __fastcall TForm1::FormPaint(TObject *Sender) {
    TPoint vertices[5];
    vertices[0] = Point(0, 0);
    vertices[1] = Point(50, 0);
    vertices[2] = Point(75, 50);
    vertices[3] = Point(25, 50);
    vertices[4] = Point(0, 0);
    Canvas->Polyline(vertices, 4);
}

Note that the last parameter to Polyline is the index of the last point, not the number of points.

See Also