FormattedText.BuildHighlightGeometry Method

Definition

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

Overloads

BuildHighlightGeometry(Point)

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

BuildHighlightGeometry(Point, Int32, Int32)

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

BuildHighlightGeometry(Point)

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

public System.Windows.Media.Geometry BuildHighlightGeometry (System.Windows.Point origin);

Parameters

origin
Point

The origin of the highlight region.

Returns

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

Examples

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(
        Text,
        CultureInfo.GetCultureInfo("en-us"),
        FlowDirection.LeftToRight,
        new Typeface(
            Font,
            fontStyle,
            fontWeight,
            FontStretches.Normal),
        FontSize,
        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 highlight.
    if (Highlight == true)
    {
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
    }
}

Remarks

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

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 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

BuildHighlightGeometry(Point, Int32, Int32)

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

public System.Windows.Media.Geometry BuildHighlightGeometry (System.Windows.Point origin, int startIndex, int count);

Parameters

origin
Point

The origin of the highlight region.

startIndex
Int32

The index of the initial character the highlight bounds should be obtained for.

count
Int32

The number of characters the highlight bounds should contain.

Returns

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

Remarks

The returned Geometry object contains only the bounding box of the highlighted text and does not contain any rendered text.

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 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