FormattedText.BuildHighlightGeometry 方法

定義

傳回 Geometry 物件,表示格式化文字的週框方塊。

多載

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

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 == 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));
    }
}
''' <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 物件,表示格式化文字子字串的反白顯示週框方塊。

備註

傳回 Geometry 的物件只包含醒目提示文字的周框方塊,而且不包含任何轉譯的文字。

適用於