[Overview][Types][Classes][Procedures and functions][Index] | Reference for unit 'ExtCtrls' (#lcl)

# TCustomShape.DrawToCanvas

Draws the Shape for the control on the specified canvas.

## Declaration

Source position: extctrls.pp line 291

`protected procedure TCustomShape.DrawToCanvas(`
`ACanvas: TCanvas`
`); virtual;`

## Description

DrawToCanvas is a method used to draw the shaped control on the TCanvas instance specified in the ACanvas argument. It calculates the drawing area (TRect) needed using the control Width and Height, the width of the Pen on the canvas, and the Shape for the control.

The Brush style and color for the canvas are set in the calling routine. This allows the same method to be used to draw either the content for the shaped control or its Monochrome mask - depending on the settings in the canvas.

DrawToCanvas calls methods in ACanvas to perform drawing operations needed for the value in Shape. For example:

stRectangle, stSquare
  Calls the Rectangle method.
stRoundRect, stRoundSquare
  Calls the RoundRect method.
stCircle, stEllipse
  Calls the Ellipse method.
stSquaredDiamond, stDiamond
  Allocates TPoint instances with the four (4) vertices needed for the shape and calls the Polygon method.
stTriangle, stTriangleDown, stTriangleLeft, stTriangleRight
  Allocates TPoint instances with the three (3) vertices needed for the shape and calls the Polygon method.
stStar, stStarDown
  Calculates the center point and radii needed to scale the width or height for the shape. Allocates the eleven (11) vertices needed for the shape and calls the Polyon method.
stPolygon
  Signals the OnShapePoints event handler (when assigned) to get the vertices and polygon winding for a user-specified or irregular polygonal shape. If the event handler returns more than 2 vertices, the Polygon method is called using the points. No actions are performed if 2 (or fewer points) are returned as vertices for the polygon. Please note that the Shape is not drawn on the control canvas at design-time; a rectangle with a dashed border and a red 'X' are drawn to the corners of the designer surface.

DrawToCanvas is called from the UpdateMask and Paint methods.

## Version info

Added in LCL version 4.0.

## See also

TCustomShape.Shape |  | Indicates the geometric shape drawn on the shaped control.
TCustomShape.Pen |  | The Pen used to draw lines on the shaped control.
TCustomShape.OnShapePoints |  | Event handler signalled to get a custom vertices for the shape drawn on the control.
TCustomShape.UpdateMask |  | Updates the internal Monochrome bitmap used as a mask to detect mouse click events on the shaped control.
TCustomShape.Paint |  | Draws the shape for the control on its Canvas.
TCanvas |  | Implements a drawing surface for a visual control or bitmap image.
TControl.Width |  | The horizontal size for the control.
TControl.Height |  | The vertical size for the control.
TRect
TPoint