語言

FormattedText.BuildHighlightGeometry 方法

定義

回傳 Geometry 一個代表格式化文字高亮邊框的物件。

多載

名稱 Description
BuildHighlightGeometry(Point)

回傳 Geometry 一個代表格式化文字高亮邊框的物件。

BuildHighlightGeometry(Point, Int32, Int32)

回傳 Geometry 一個物件,代表指定格式化文字子串的重點邊界框。

BuildHighlightGeometry(Point)

回傳 Geometry 一個代表格式化文字高亮邊框的物件。

public:
 System::Windows::Media::Geometry ^ BuildHighlightGeometry(System::Windows::Point origin);
public System.Windows.Media.Geometry BuildHighlightGeometry(System.Windows.Point origin);
member this.BuildHighlightGeometry : System.Windows.Point -> System.Windows.Media.Geometry
Public Function BuildHighlightGeometry (origin As Point) As Geometry

參數

origin
Point

高光區的起源。

傳回

代表 Geometry 格式化文字高亮邊界框的物件。

範例

以下範例說明如何建立 FormattedText 物件,並取得格式化文字及其邊界框的幾何形狀。

/// <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) fontWeight = FontWeights.Bold;
    if (Italic) 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)
    {
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
    }
}
''' <summary>
''' Create the outline geometry based on the formatted text.
''' </summary>
Public Sub CreateText()
    Dim fontStyle As FontStyle = FontStyles.Normal
    Dim fontWeight As FontWeight = FontWeights.Medium

    If Bold = True Then
        fontWeight = FontWeights.Bold
    End If
    If Italic = True Then
        fontStyle = FontStyles.Italic
    End If

    ' Create the formatted text based on the properties set.
    Dim formattedText As New FormattedText(Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface(Font, fontStyle, fontWeight, FontStretches.Normal), FontSize, 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 Point(0, 0))

    ' Build the geometry object that represents the text highlight.
    If Highlight = True Then
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(New Point(0, 0))
    End If
End Sub

備註

邊界框區域包含從指定 origin點開始的整個格式化文字區域。 回傳 Geometry 的物件僅包含高亮文字的邊界框,且不包含任何渲染文字。

以下範例說明了一種透過修改轉換後文字的筆劃與高亮來創造視覺效果的方法。

文字筆觸上畫筆 文字筆觸上畫筆 文字 文字筆觸上畫筆畫筆在筆觸和高光上應用的範例

適用於

BuildHighlightGeometry(Point, Int32, Int32)

回傳 Geometry 一個物件,代表指定格式化文字子串的重點邊界框。

public:
 System::Windows::Media::Geometry ^ BuildHighlightGeometry(System::Windows::Point origin, int startIndex, int count);
public System.Windows.Media.Geometry BuildHighlightGeometry(System.Windows.Point origin, int startIndex, int count);
member this.BuildHighlightGeometry : System.Windows.Point * int * int -> System.Windows.Media.Geometry
Public Function BuildHighlightGeometry (origin As Point, startIndex As Integer, count As Integer) As Geometry

參數

origin
Point

高光區的起源。

startIndex
Int32

應取得首字母索引,高亮界限。

count
Int32

高亮範圍應包含的字元數。

傳回

Geometry代表格式化文字子串高亮邊界框的物件。

備註

回傳 Geometry 的物件僅包含高亮文字的邊界框,且不包含任何渲染文字。

適用於