TextRun 類別

定義

表示共用單一屬性集的字元序列。

public ref class TextRun abstract
public abstract class TextRun
type TextRun = class
Public MustInherit Class 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 的每個類別都代表不同類型的文字內容。

執行個體 說明
TextRun 階層的根目錄。 定義共用相同字元屬性集的字元群組。
TextCharacters 定義來自不同實體字樣之字元字元的集合。
TextEmbeddedObject 定義一種文字內容類型,其中測量、點擊測試及繪製整個內容會做為不同的實體。 這種類型的內容範例是文字行中間的按鈕。
TextEndOfLine 定義分行符號代碼。
TextEndOfParagraph 定義段落分隔字元代碼。 衍生自 TextEndOfLine
TextEndOfSegment 定義區段中斷標記。
TextHidden 定義非可見字元的範圍。
TextModifier 定義修改範圍的開頭。

建構函式

TextRun()

建立 TextRun 物件的執行個體。

屬性

CharacterBufferReference

取得文字執行字元緩衝區的參考。

Length

文字執行中的字元數目。

Properties

取得文字執行中每個字元所共用的文字屬性集,如字樣或前景筆刷。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱