Drawing Rectangles and Ellipses

From RAD Studio
Jump to: navigation, search

Go Up to Drawing Shapes


To draw a rectangle or ellipse on a canvas, call the canvas's Rectangle method or Ellipse method, passing the coordinates of a bounding rectangle.

The Rectangle method draws the bounding rectangle; Ellipse draws an ellipse that touches all sides of the rectangle.

The following method draws a rectangle filling a form's upper left quadrant, then draws an ellipse in the same area:

void __fastcall TForm1::FormPaint(TObject *Sender)
{
    Canvas->Rectangle(0, 0, ClientWidth/2, ClientHeight/2);
    Canvas->Ellipse(0, 0, ClientWidth/2, ClientHeight/2);
}

See Also