RAD Studio |  |

Drawing a Polygon in a VCL Forms Application
See Also
Collapse All

This procedure draws a polygon in a VCL form.

1. Create a VCL form.
2. Code the form's OnPaint event handler to draw a polygon.
3. Build and run the application.

To create a VCL form

1. Choose FileNewOtherDelphi Projects or C++Builder Projects and double-click the VCL Forms Application icon. The VCL Forms Designer is displayed.
2. In the form view, click the form, if necessary, to display Form1 in the Object Inspector.

To write the OnPaint event handler

1. In the Object Inspector, click the Events tab.
2. Double-click the OnPaint event. The Code Editor displays with the cursor in the TForm1.FormPaint (Delphi) or TForm1::FormPaint (C++) event handler block.
3. Enter the following event handling code:

Copy Code

    Canvas.Polygon ([Point(0,0), Point(0, ClientHeight),
    Point(ClientWidth, ClientHeight)]);

Copy Code

    TPoint points[] = { Point(0,0),
                        Point(0, ClientHeight),
                        Point(ClientWidth, ClientHeight) };
    Canvas->Polygon( points, 3 );

To run the program

1. Select RunRun.
2. The applications executes, displaying a right triangle in the lower left half of the form.

See Also

VCL Overview

Drawing Straight Lines In a VCL Forms Application

Drawing Rectangles and Ellipses in a VCL Forms Application

Displaying a Bitmap Image in a VCL Forms Application

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!