VisualStyleRenderer.GetTextExtent Method

Definition

Returns the size and location of the specified string when drawn with the font of the current visual style element.

Overloads

GetTextExtent(IDeviceContext, String, TextFormatFlags)

Returns the size and location of the specified string when drawn with the font of the current visual style element.

GetTextExtent(IDeviceContext, Rectangle, String, TextFormatFlags)

Returns the size and location of the specified string when drawn with the font of the current visual style element within the specified initial bounding rectangle.

GetTextExtent(IDeviceContext, String, TextFormatFlags)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Returns the size and location of the specified string when drawn with the font of the current visual style element.

C#
public System.Drawing.Rectangle GetTextExtent(System.Drawing.IDeviceContext dc, string textToDraw, System.Windows.Forms.TextFormatFlags flags);

Parameters

dc
IDeviceContext

The IDeviceContext this operation will use.

textToDraw
String

The string to measure.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

Returns

A Rectangle that contains the area required to fit the rendered text.

Exceptions

dc is null.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

GetTextExtent(IDeviceContext, Rectangle, String, TextFormatFlags)

Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs
Source:
VisualStyleRenderer.cs

Returns the size and location of the specified string when drawn with the font of the current visual style element within the specified initial bounding rectangle.

C#
public System.Drawing.Rectangle GetTextExtent(System.Drawing.IDeviceContext dc, System.Drawing.Rectangle bounds, string textToDraw, System.Windows.Forms.TextFormatFlags flags);

Parameters

dc
IDeviceContext

The IDeviceContext this operation will use.

bounds
Rectangle

A Rectangle used to control the flow and wrapping of the text.

textToDraw
String

The string to measure.

flags
TextFormatFlags

A bitwise combination of the TextFormatFlags values.

Returns

A Rectangle that contains the area required to fit the rendered text.

Exceptions

dc is null.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10