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

注釈

テキスト実行は、1 つのプロパティ セットを共有する一連の文字です。 フォント ファミリ、フォント スタイル、前景色、テキスト装飾、その他の書式設定効果など、書式を変更すると、テキストランが中断されます。 TextRun クラスは、TextFormatterによって処理される複数の種類のテキスト コンテンツを表す型階層のルートです。 TextRunから派生した各クラスは、個別の種類のテキスト コンテンツを表します。

クラス Description
TextRun 階層のルート。 同じ文字プロパティ のセットを共有する文字のグループを定義します。
TextCharacters 個別の物理書体から文字グリフのコレクションを定義します。
TextEmbeddedObject コンテンツ全体の測定、ヒット テスト、描画を個別のエンティティとして実行するテキスト コンテンツの種類を定義します。 この種類のコンテンツの例として、テキスト行の中央にあるボタンがあります。
TextEndOfLine 改行文字コードを定義します。
TextEndOfParagraph 段落区切り文字コードを定義します。 TextEndOfLineから派生します。
TextEndOfSegment セグメント区切りマーカーを定義します。
TextHidden 表示されない文字の範囲を定義します。
TextModifier 変更スコープの先頭を定義します。

適用対象