BuildHighlightGeometry Method (Point)

FormattedText.BuildHighlightGeometry Method (Point)


Returns a Geometry object that represents the highlight bounding box of the formatted text.

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public Geometry BuildHighlightGeometry(
	Point origin


Type: System.Windows.Point

The origin of the highlight region.

Return Value

Type: System.Windows.Media.Geometry

The Geometry object that represents the highlight bounding box of the formatted text.

The bounding box region contains the entire formatted text area starting at the point specified by origin. The returned Geometry object contains only the bounding box of the highlighted text and does not contain any rendered text.

The following example illustrates a way to creating visual effects by modifying the stroke and highlight of converted text.

Text with image brush applied to stroke

Example of an image brush applied to the stroke and highlight

The following example shows how to create a FormattedText object and to retrieve the geometries of the formatted text and its bounding box.

/// <summary>
/// Create the outline geometry based on the formatted text.
/// </summary>
public void CreateText()
    System.Windows.FontStyle fontStyle = FontStyles.Normal;
    FontWeight fontWeight = FontWeights.Medium;

    if (Bold == true) fontWeight = FontWeights.Bold;
    if (Italic == true) fontStyle = FontStyles.Italic;

    // Create the formatted text based on the properties set.
    FormattedText formattedText = new FormattedText(
        new Typeface(
        System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. 

    // Build the geometry object that represents the text.
    _textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

    // Build the geometry object that represents the text hightlight.
    if (Highlight == true)
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));

.NET Framework
Available since 3.0
Return to top
© 2015 Microsoft