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

# TCanvas

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

TCanvas - where most of the drawing is performed

## Declaration

Source position: graphics.pp line 961

`type TCanvas = class(TFPCustomCanvas)`
`protected`
`function DoCreateDefaultFont; override;` |  | DoCreateDefaultFont - calls TFont.Create to create a default fomt
`function DoCreateDefaultPen; override;` |  | DoCreateDefaultPen - calls TPen.Create to create a default pen
`function DoCreateDefaultBrush; override;` |  | DoCreateDefaultBrush - calls TBrush.Create to create a default brush
`procedure SetColor(); override;` |  | SetColor converts the specified FPColor to a Color and applies it to the pixels at x, y
`function GetColor(); override;` |  | GetColor - finds the Color of the pixels at x, y and returns the value converted to a FPColor
`procedure SetHeight(); override;` |  | SetHeight - should never be called for Canvas: raises an exception if it is called
`function GetHeight; override;` |  | GetHeight - if a handle has been allocated, returns the height from the device size
`procedure SetWidth(); override;` |  | SetWidth - should never be called; raises an exception if it is called
`function GetWidth; override;` |  | GetWidth - if a handle has been allocated, returns the width from the device size
`procedure SetPenPos(); override;` |  | SetPenPos moves pen to specified position
`procedure DoLockCanvas; override;` |  | DoLockCanvas - enters critical locking section then calls inherited method
`procedure DoUnlockCanvas; override;` |  | DoUnlockCanvas - leaves the critical locking section then calls inherited method
`procedure DoTextOut(); override;` |  | DoTextOut calls TextOut for the specified coordinates and string
`procedure DoGetTextSize(); override;` |  | DoGetTextSize calls TextExtent to find width and height of specified text string
`function DoGetTextHeight(); override;` |  | DoGetTextHeight calls TextHeight to return the height of the text
`function DoGetTextWidth(); override;` |  | DoGetTextWidth calls TextWidth to return the width of the given text string
`procedure DoRectangle(); override;` |  | DoRectangle calls Frame to draw a rectangle in the given bounds
`procedure DoRectangleFill(); override;` |  | DoRectangleFill calls FillRect to draw a filled rectangle with the given bounds
`procedure DoRectangleAndFill(); override;` |  | DoRectangleAndFill - calls Rectangle to draw a rectangle and fill it
`procedure DoEllipse(); override;` |  | DoEllipse draws an Arc of 360 degrees within given Bounds, making an ellipse
`procedure DoEllipseFill(); override;` |  | DoEllipseFill calls Ellipse
`procedure DoEllipseAndFill(); override;` |  | DoEllipseAndFill - calls inherited DoEllipseAndFill
`procedure DoPolygon(); override;` |  | DoPolygon calls PolyLine to draw a series of lines through the points
`procedure DoPolygonFill(); override;` |  | DoPolygonFill calls Polygon for the suppied points
`procedure DoPolygonAndFill(); override;` |  | DoPolygonAndFill calls inherited method
`procedure DoPolyline(); override;` |  | DoPolyline calls PolyLine
`procedure DoFloodFill(); override;` |  | DoFloodFill calls FloodFill
`procedure DoMoveTo(); override;` |  | DoMoveTo calls MoveTo
`procedure DoLineTo(); override;` |  | DoLineTo calls LineTo
`procedure DoLine(); override;` |  | DoLine calls Line to draw from x1, y1 to x2, y2
`procedure DoCopyRect(); override;` |  | DoCopyRect checks that SrcCanvas is of correct type then copies coordinates and calls CopyRect
`procedure DoDraw(); override;` |  | DoDraw checks that Image is of the right type, makes a local copy, creates the necessary handles and bitmaps for drawing
`procedure CheckHelper(); override;` |  | CheckHelper - ignored by current class
`function GetClipRect; override;` |  | GetClipRect - if an error is encountered in finding the Clipping Rectangle dimensions, sets some defaults anyway
`procedure SetClipRect(); override;`
`function GetClipping; override;` |  | GetClipping returns True if clipping is being performed
`procedure SetClipping(); override;` |  | SetClipping specifies (via boolean argument) whether clipping is to be performed
`function GetPixel(); virtual;` |  | GetPixel - retuns the colour of the pixel at the specified location
`procedure CreateBrush; virtual;` |  | CreateBrush creates necessary handles, sets up local defaults for style, hatching, background colour
`procedure CreateFont; virtual;` |  |
`procedure CreateHandle; virtual;` |  | CreateHandle - greates a new Handle for the Canvas
`procedure CreatePen; virtual;` |  | CreatePen sets up local handles and defaults for Pen creation, sets initial position of Pen
`procedure CreateRegion; virtual;` |  | CreateRegion - creates a rectangular region for the Canvas
`procedure DeselectHandles; virtual;` |  | DeselectHandles - remove from group of selected handles
`procedure PenChanging(); virtual;` |  | PenChanging - software emulation for call to OnChanging event for Pen
`procedure FontChanging(); virtual;` |  | FontChanging - software emulation for call to OnChanging event for Font
`procedure BrushChanging(); virtual;` |  | BrushChanging - software emulation for call to OnChanging event for Brush
`procedure RegionChanging(); virtual;` |  | RegionChanging - software emulation for call to OnChanging event for Region
`procedure RealizeAutoRedraw; virtual;` |  | RealizeAutoRedraw - implement the AutoDraw feature
`procedure RealizeAntialiasing; virtual;` |  | RealizeAntialiasing - implement the Anti-aliasing feature
`procedure RequiredState(); virtual;` |  | RequiredState - the set of Canvas State required (csHandleValid, csFontValid, csPenvalid, csBrushValid, csRegionValid)
`procedure SetHandle(); virtual;` |  | SetHandle - specify a Handle
`procedure SetInternalPenPos(); virtual;` |  | SetInternalPenPos - specify position for the Pen
`procedure SetPixel(); virtual;` |  | SetPixel - specify a colour for the stated pixel
`procedure FreeHandle; virtual;` |  | FreeHandle - release a Handle
`public`
`constructor Create;` |  | Create - constructor for TCanvas: calls inherited Create and sets defaults for many properties and actions
`destructor Destroy; override;` |  | Destroy - destructor for TCanvas: frees handles and region, calls inherited Destroy, sets font, pen and brush resources to nil
`procedure Lock; virtual;` |  | Lock the canvas, making it unavailble for drawing
`function TryLock;` |  | TryLock - examines the Lock state, and performs Lock if necessary
`procedure Unlock; virtual;` |  | Unlock or release a previously locked Canvas
`procedure Refresh; virtual;` |  | Refresh the drawing of the Canvas
`procedure Changing; virtual;` |  | Changing - software emulation of a call to the OnChanging event
`procedure Changed; virtual;` |  | Changed - software emulation of a call to the OnChange event
`procedure SaveHandleState; virtual;` |  | SaveHandleState - stores the state of the Handle
`procedure RestoreHandleState; virtual;` |  | RestoreHandleState - retrieves the saved state of the Handle
`procedure Arc();` |  | Use Arc to draw an elliptically curved line with the current Pen
`procedure Chord();` |  | Chord draws a filled Chord-shape on the canvas
`procedure CopyRect(); virtual;` |  | Copies the rectangle found at Source in SrcCanvas to the destination position Dest
`procedure Draw(); virtual;` |  | Draw - copies bounds from SrcGraphic, then calls StretchDraw to perform the drawing
`procedure DrawFocusRect(); virtual;` |  | DrawFocusRect - draws a focused rectangle at the specified position
`procedure StretchDraw(); virtual;` |  | StretchDraw - uses the Draw method of the source graphic (TGraphic)
`procedure Ellipse();` |  | Ellipse draws a filled circle or ellipse on the canvas
`procedure FillRect();` |  | FillRect - draw a filled rectangle in the specified coordinate space
`procedure FloodFill(); virtual;` |  | FloodFill flood-fills an area with the given colour, starting from the specified point; uses the FloodFill method for the current interface or widget set
`procedure Frame3d(); virtual;` |  | Frame3d - produce a frame with 3-D effect (with bevelled edges etc) in the specified rectangle
`procedure Frame();` |  | Produce a Frame or border around the specified rectangle using a Pen
`procedure FrameRect();` |  | FrameRect - produce a border around the specified rectangle using a Brush
`procedure GradientFill();` |  | GradientFill - fill the specified rectangle with the specified colours in a gradient with the specified direction
`procedure RadialPie(); virtual;` |  | RadialPie uses Pie to draw a filled pie-shaped wedge on the canvas
`procedure Pie(); virtual;` |  | Pie draws a filled Pie-shaped wedge on the canvas
`procedure PolyBezier();` |  | Polybezier draws cubic Bezier curves
`procedure Polygon();` |  | Polygon draws a closed, many-sided shape on the canvas, using the value of Pen
`procedure Polyline();` |  | Polyline connects a set of points on the canvas
`procedure Rectangle();` |  | Draws a Rectangle at the specified coordinates
`procedure RoundRect();` |  | RoundRect - draws a rectangle at the specified position, with corners rounded by the factors RX, RY
`procedure TextOut(); virtual;` |  | Writes the Text string at the position X, Y on the canvas and leaves the pen at the end of the text; uses the ExtUTF8Out method of the current interface or widget set
`procedure TextRect();` |  | Writes Text string within a specified rectangle, according to predefined Style
`function TextExtent(); virtual;` |  | TextExtent - returns the total size of the specified text
`function TextHeight(); virtual;` |  | TextHeight - returns the height of the specified text
`function TextWidth(); virtual;` |  | TextWidth - returns the width of the specified text
`function HandleAllocated; virtual;` |  | HandleAllocated - returns True if a handle has been allocated
`function GetUpdatedHandle(); virtual;` |  | GetUpdatedHandle - returns the value of the updated Handle
`property Pixels: TColor; [rw]` |  | The colour of the Pixels located at the specified position
`property Handle: HDC; [rw]` |  | The operating system Handle for this object
`property TextStyle: TTextStyle; [rw]` |  | The TextStyle to be used in this Canvas
`published`
`property AntialiasingMode: TAntialiasingMode; [rw]` |  | AntialiasingMode - anti-aliasing on, off or don't care
`property AutoRedraw: Boolean; [rw]` |  | AutoRedraw - if True, the Canvas is to be redrawn automatically after each change or update
`property Brush: TBrush; [rw]` |  | The Brush to be used for painting this Canvas
`property CopyMode: TCopymode; [rw]` |  | The CopyMode to be used (arbitrary number)
`property Font: TFont; [rw]` |  | The Font to be used for text in this canvas
`property Height: Integer; [r]` |  | The Height of the canvas
`property Pen: TPen; [rw]` |  | The Pen to be used for writing in this canvas
`property Region: TRegion; [rw]` |  | The Regionwhere the Canvas is located
`property Width: Integer; [r]` |  | The Width of the Canvas
`property OnChange: TNotifyEvent; [rw]` |  | Event handler for a change in the canvas
`property OnChanging: TNotifyEvent; [rw]` |  | Event handler while canvas is changing
`end;`

## Inheritance

`TCanvas` |  | TCanvas - where most of the drawing is performed
`TFPCustomCanvas`
`TObject`

## Description

TCanvas is a class that defines a very large number of drawing methods including methods for pen and colour selection, producing shapes and filling them, setting or clearing individual pixels, and producing graphic text.

The latest version of this document can be found at lazarus-ccr.sourceforge.net.