Drawing a Polygon in a VCL Forms Application
Go Up to How To Build a VCL Forms Application with Graphics
This procedure draws a polygon in a VCL form.
- Create a VCL form.
- Code the form's OnPaint event handler to draw a polygon.
- Build and run the application.
To create a VCL form
- Choose File > New > Other > Delphi Projects or C++Builder Projects and double-click the VCL Forms Application icon.The VCL Forms Designer is displayed.
- In the form view, click the form, if necessary, to display Form1 in the Object Inspector.
To write the OnPaint event handler
- In the Object Inspector, click the Events tab.
- Double-click the OnPaint event.The Code Editor displays with the cursor in the TForm1.FormPaint (Delphi) or TForm1::FormPaint (C++) event handler block.
- Enter the following event handling code:
Canvas.Polygon ([Point(0,0), Point(0, ClientHeight), Point(ClientWidth, ClientHeight)]); TPoint points[] = { Point(0,0), Point(0, ClientHeight), Point(ClientWidth, ClientHeight) }; Canvas->Polygon( points, 3 );
To run the program
- Select Run > Run .
- The applications executes, displaying a right triangle in the lower left half of the form.