語言

TextSource.GetTextRun(Int32) 方法

定義

在指定TextRun位置取得起始點TextSource。

public:
 abstract System::Windows::Media::TextFormatting::TextRun ^ GetTextRun(int textSourceCharacterIndex);
public abstract System.Windows.Media.TextFormatting.TextRun GetTextRun(int textSourceCharacterIndex);
abstract member GetTextRun : int -> System.Windows.Media.TextFormatting.TextRun
Public MustOverride Function GetTextRun (textSourceCharacterIndex As Integer) As TextRun

參數

textSourceCharacterIndex
Int32

指定在 中擷取 的TextSource字元索引位置TextRun。

傳回

一個代表 TextRun、 或由 TextRun衍生的物件的值。

範例

以下範例中,實作了該方法的 GetTextRun 覆寫。

// Retrieve the next formatted text run for the text source.
public override TextRun GetTextRun(int textSourceCharacterIndex)
{
    // Determine whether the text source index is in bounds.
    if (textSourceCharacterIndex < 0)
    {
        throw new ArgumentOutOfRangeException("textSourceCharacterIndex", "Value must be greater than 0.");
    }

    // Determine whether the text source index has exceeded or equaled the text source length.
    if (textSourceCharacterIndex >= _text.Length)
    {
        // Return an end-of-paragraph indicator -- a TextEndOfParagraph object is a special type of text run.
        return new TextEndOfParagraph(1);
    }

    // Create and return a TextCharacters object, which is formatted according to
    // the current layout and rendering properties.
    if (textSourceCharacterIndex < _text.Length)
    {
        // The TextCharacters object is a special type of text run that contains formatted text.
        return new TextCharacters(
           _text,                                       // The text store
           textSourceCharacterIndex,                    // The text store index
           _text.Length - textSourceCharacterIndex,     // The text store length
           new CustomTextRunProperties());              // The layout and rendering properties
    }

    // Return an end-of-paragraph indicator if there is no more text source.
    return new TextEndOfParagraph(1);
}
' Retrieve the next formatted text run for the text source.
Public Overrides Function GetTextRun(ByVal textSourceCharacterIndex As Integer) As TextRun
    ' Determine whether the text source index is in bounds.
    If textSourceCharacterIndex < 0 Then
        Throw New ArgumentOutOfRangeException("textSourceCharacterIndex", "Value must be greater than 0.")
    End If

    ' Determine whether the text source index has exceeded or equaled the text source length.
    If textSourceCharacterIndex >= _text.Length Then
        ' Return an end-of-paragraph indicator -- a TextEndOfParagraph object is a special type of text run.
        Return New TextEndOfParagraph(1)
    End If

    ' Create and return a TextCharacters object, which is formatted according to
    ' the current layout and rendering properties.
    If textSourceCharacterIndex < _text.Length Then
        ' The TextCharacters object is a special type of text run that contains formatted text.
        Return New TextCharacters(_text, textSourceCharacterIndex, _text.Length - textSourceCharacterIndex, New CustomTextRunProperties()) ' The layout and rendering properties -  The text store length -  The text store index -  The text store
    End If

    ' Return an end-of-paragraph indicator if there is no more text source.
    Return New TextEndOfParagraph(1)
End Function

備註

文字執行是一連串字元共用單一屬性集合。 任何格式的變更,例如字型族、字型樣式、前景顏色、文字裝飾或其他格式效果,都會破壞文字串連。 該 TextRun 類別是型別階層的根節點,代表多種由 處理 TextFormatter的文字內容類型。 每個衍生的 TextRun 類別代表一種不同類型的文字內容。

Class Description
TextRun 階級的根源。 定義一組擁有相同屬性的字元。
TextCharacters 定義來自特定實體字體的字形集合。
TextEmbeddedObject 定義了一種文字內容類型,將測量、點擊測試及繪製整個內容視為獨立的整體。 這類內容的例子是文字行中間的按鈕。
TextEndOfLine 定義換行字元代碼。
TextEndOfParagraph 定義段落分隔字元代碼。 衍生自 TextEndOfLine。
TextEndOfSegment 定義了一段中斷標記。
TextHidden 定義一系列非視覺字元。
TextModifier 定義修改範圍的起始。

適用於