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

# TCanvas.TextExtent

Calculates the width and height for the specified Text using the Font for the canvas.

## Declaration

Source position: graphics.pp line 1162

`public function TCanvas.TextExtent(`
`const Text: string`
`):TSize; virtual;`

## Arguments

`Text` |  | Text examined and measured in the method.

## Function result

TSize instance with the Width and Height for the text.

## Description

TextExtent is a TSize function used to get the width and height for the specified Text using the Font for the canvas instance.

The TSize type in the return value returns the Width and Height for the Text in pixels using the cX (Width) and cY (Height) members. Both members are set to 0 if Text is an empty string (''), and when either the Handle or Font for the canvas are invalid. The CreateHandle and CreateFont methods are called to attempt to create the items when needed.

If the Font has the default un-initialized settings, the OnGetSystemFont event handler is signalled to get the default system font selected for the canvas.

TextExtent calls the GetTextExtentPoint routine in the widgetset interface to get the return value for the method.

TextExtent is used in methods like TextWidth, TextHeight and DoGetTextSize.

## See also

TCanvas.RequiredState |  | Ensures that all handles needed for the canvas are valid.
TCanvas.Handle |  | Handle (or device context) for the drawing surface.
TCanvas.Font |  | Contains the Font used to render text on the drawing surface.
TCanvas.CreateHandle |  | Creates a new Handle for the Canvas.
TCanvas.CreateFont |  | Ensures that the Font for the canvas is valid and uses the correct color.
TCanvas.TextWidth |  | Gets the width for the specified text using the canvas Font.
TCanvas.TextHeight |  | Gets the height for the specified text using the canvas Font.
TCanvas.DoGetTextSize |  | Calls TextExtent to find the width and height of the specified text.
OnGetSystemFont |  | Address of the routine used to get the handle for the system font.