Graphics.MeasureCharacterRanges Method

Gets an array of Region objects, each of which bounds a range of character positions within the specified string.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public:
array<Region^>^ MeasureCharacterRanges (
	String^ text, 
	Font^ font, 
	RectangleF layoutRect, 
	StringFormat^ stringFormat
)
public Region[] MeasureCharacterRanges (
	String text, 
	Font font, 
	RectangleF layoutRect, 
	StringFormat stringFormat
)
public function MeasureCharacterRanges (
	text : String, 
	font : Font, 
	layoutRect : RectangleF, 
	stringFormat : StringFormat
) : Region[]
Not applicable.

Parameters

text

String to measure.

font

Font that defines the text format of the string.

layoutRect

RectangleF structure that specifies the layout rectangle for the string.

stringFormat

StringFormat that represents formatting information, such as line spacing, for the string.

Return Value

This method returns an array of Region objects, each of which bounds a range of character positions within the specified string.

The regions returned by this method are resolution-dependent, so there might be a slight loss of accuracy if strings are recorded in a metafile at one resolution and later played back at a different resolution.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code performs the following actions:

  • Sets a string "First and Second ranges" and a font for display of the string ("Times New Roman", 16 point).

  • Sets two character ranges within the string (which correspond to the words "First" and "Second").

  • Creates a rectangle in which to display the string.

  • Sets the formatting of the string ¾ including the two character ranges.

  • Draws the string to the screen.

  • Measures the character ranges, determines rectangles that bound the two specified ranges.

  • Draws the two rectangles to the screen.

The result is the displayed string with the first range ("First") bounded by a red rectangle and the second range ("Second") bounded by a blue rectangle.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show: