TextSource.GetTextRun(Int32) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar en TextRun start vid en angiven TextSource position.
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
Parametrar
- textSourceCharacterIndex
- Int32
Anger teckenindexpositionen i den TextSource plats där TextRun den hämtas.
Returer
Ett värde som representerar ett TextRun, eller ett objekt som härletts från TextRun.
Exempel
I följande exempel implementeras en åsidosättning för GetTextRun metoden.
// 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
Kommentarer
En textkörning är en sekvens med tecken som delar en enda egenskapsuppsättning. Alla ändringar i formatet, till exempel teckensnittsfamilj, teckensnittsstil, förgrundsfärg, textdekoration eller någon annan formateringseffekt, bryter textkörningen. Klassen TextRun är roten i en typhierarki som representerar flera typer av textinnehåll som bearbetas av TextFormatter. Varje klass som härleds från TextRun representerar en distinkt typ av textinnehåll.
| Class | Description |
|---|---|
| TextRun | Hierarkins rot. Definierar en grupp med tecken som delar samma uppsättning teckenegenskaper. |
| TextCharacters | Definierar en samling teckengenlyfer från ett distinkt fysiskt typsnitt. |
| TextEmbeddedObject | Definierar en typ av textinnehåll där mätning, träfftestning och ritning av hela innehållet görs som en distinkt entitet. Ett exempel på den här typen av innehåll är en knapp i mitten av textraden. |
| TextEndOfLine | Definierar en radbrytningsteckenkod. |
| TextEndOfParagraph | Definierar en styckebrytningsteckenkod. Härleds från TextEndOfLine. |
| TextEndOfSegment | Definierar en brytmarkör för segment. |
| TextHidden | Definierar ett intervall med icke-synliga tecken. |
| TextModifier | Definierar början av ett ändringsomfång. |