TextRun Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a sequence of characters that share a single property set.
public ref class TextRun abstract
public abstract class TextRun
type TextRun = class
Public MustInherit Class TextRun
- Inheritance
-
TextRun
- Derived
In the following example, an override for the GetTextRun method is implemented.
// 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
A text run is a sequence of characters sharing a single property set. Any change to the format, such as font style, foreground color, font family, or any other formatting effect, breaks the text run. The following example illustrates how changes in formatting to a text string results in a series of text runs - each text run has a common set of formatting properties.
The TextRun class is the root of a type hierarchy representing several types of text content processed by TextFormatter. Each class that is derived from TextRun represents a distinct type of text content.
Class | Description |
---|---|
TextRun | Root of the hierarchy. Defines a group of characters that share the same set of character properties. |
TextCharacters | Defines a collection of character glyphs from a distinct physical typeface. |
TextEmbeddedObject | Defines a type of text content in which measuring, hit testing, and drawing of the entire content is done as a distinct entity. An example of this type of content is a button in the middle of the line of text. |
TextEndOfLine | Defines a line-break character code. |
TextEndOfParagraph | Defines a paragraph-break character code. Derives from TextEndOfLine. |
TextEndOfSegment | Defines a segment break marker. |
TextHidden | Defines a range of non-visible characters. |
TextModifier | Defines the beginning of a modification scope. |
Character |
Gets a reference to the text run character buffer. |
Length |
Gets the number of characters in the text run. |
Properties |
Gets the set of text properties that are shared by every character in the text run, such as typeface or foreground brush. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Producto | Versiones |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: