Show: Delphi C++
Display Preferences

Drawing Rectangles and Ellipses in a VCL Forms Application

From RAD Studio
Jump to: navigation, search

Go Up to How To Build a VCL Forms Application with Graphics

This procedure draws a rectangle and ellipse in a VCL form.

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

To create a VCL form and place an image on it

  1. Choose File > New > Other > Delphi 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, double-click the Form1 OnPaint event on the Events tab.The Code Editor displays with the cursor in the TForm1.FormPaint (Delphi) or TForm1::FormPaint (C++) event handler block.
  2. Enter the following event handling code:
Canvas.Rectangle (0, 0, ClientWidth div 2, ClientHeight div 2);
Canvas.Ellipse (0, 0, ClientWidth div 2, ClientHeight div 2);
Canvas->Rectangle( 0, 0, ClientWidth / 2, ClientHeight / 2 );
Canvas->Ellipse( 0, 0, ClientWidth / 2, ClientHeight / 2 );

To run the program

  1. Choose Run > Run .
  2. The applications executes, displaying a rectangle in the upper left quadrant, and an ellipse in the same area of the form.

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance