TextSource.GetTextRun(Int32) Methode

Definition

Ruft einen TextRun Anfang an einer angegebenen TextSource Position ab.

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

Parameter

textSourceCharacterIndex
Int32

Gibt die Indexposition des Zeichens an, an der TextSource die TextRun Position abgerufen wird.

Gibt zurück

Ein Wert, der ein TextRunoder ein objekt darstellt, das von TextRun.

Beispiele

Im folgenden Beispiel wird eine Außerkraftsetzung für die GetTextRun Methode implementiert.

// 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

Hinweise

Ein Textlauf ist eine Abfolge von Zeichen, die einen einzelnen Eigenschaftensatz gemeinsam verwenden. Jede Änderung des Formats, z. B. Schriftfamilie, Schriftschnitt, Vordergrundfarbe, Textgestaltung oder andere Formatierungseffekte, bricht den Textlauf auf. Die TextRun Klasse ist der Stamm einer Typhierarchie, die mehrere Typen von Textinhalten darstellt, die von TextFormatter. Jede von der Klasse abgeleitete TextRun Klasse stellt einen unterschiedlichen Textinhaltstyp dar.

Class Description
TextRun Stamm der Hierarchie. Definiert eine Gruppe von Zeichen, die denselben Satz von Zeicheneigenschaften gemeinsam verwenden.
TextCharacters Definiert eine Auflistung von Zeichenglyphen aus einer eindeutigen physischen Schriftart.
TextEmbeddedObject Definiert einen Textinhaltstyp, bei dem das Messen, Treffertests und Zeichnen des gesamten Inhalts als eine unterschiedliche Entität erfolgt. Ein Beispiel für diesen Inhaltstyp ist eine Schaltfläche in der Mitte der Textzeile.
TextEndOfLine Definiert einen Zeilenumbruchzeichencode.
TextEndOfParagraph Definiert einen Absatztrennzeichencode. Wird von TextEndOfLineabgeleitet.
TextEndOfSegment Definiert eine Abschnittsumbruchmarkierung.
TextHidden Definiert einen Bereich von nicht sichtbaren Zeichen.
TextModifier Definiert den Anfang eines Änderungsbereichs.

Gilt für: