TextPointer.GetPositionAtOffset Méthode

Définition

Renvoie un TextPointer à la position indiquée par l'offset spécifié, dans les symboles, à partir du début du contenu.

Surcharges

GetPositionAtOffset(Int32, LogicalDirection)

Renvoie un TextPointer à la position indiquée par l'offset spécifié, dans les symboles, à partir du début du TextPointeractuel et dans la direction spécifiée.

GetPositionAtOffset(Int32)

Renvoie un TextPointer à la position indiquée par l'offset spécifié, dans les symboles, à partir du début du TextPointeractuel.

GetPositionAtOffset(Int32, LogicalDirection)

Renvoie un TextPointer à la position indiquée par l'offset spécifié, dans les symboles, à partir du début du TextPointeractuel et dans la direction spécifiée.

public:
 System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset, System::Windows::Documents::LogicalDirection direction);
public System.Windows.Documents.TextPointer GetPositionAtOffset (int offset, System.Windows.Documents.LogicalDirection direction);
member this.GetPositionAtOffset : int * System.Windows.Documents.LogicalDirection -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer, direction As LogicalDirection) As TextPointer

Paramètres

offset
Int32

Un offset, dans les symboles, pour lequel calculer et renvoyer la position. Si l'offset est négatif, le TextPointer retourné précède le TextPointeractuel ; sinon, il suit.

direction
LogicalDirection

L'une des valeurs LogicalDirectionqui spécifient la direction logique du TextPointerretourné.

Retours

Un TextPointer à la position indiquée par le décalage spécifié, ou null si le décalage s’étend au-delà de la fin du contenu.

Remarques

L’un des éléments suivants est considéré comme un symbole :

  • Balise ouvrante ou fermante pour l’élément TextElement .

  • Élément UIElement contenu dans un InlineUIContainer ou .BlockUIContainer Notez qu’un UIElement tel est toujours compté comme un seul symbole ; tout contenu ou élément supplémentaire contenu par le UIElement ne sont pas comptés comme symboles.

  • Caractère Unicode 16 bits à l’intérieur d’un élément de texte Run .

Voir aussi

S’applique à

GetPositionAtOffset(Int32)

Renvoie un TextPointer à la position indiquée par l'offset spécifié, dans les symboles, à partir du début du TextPointeractuel.

public:
 System::Windows::Documents::TextPointer ^ GetPositionAtOffset(int offset);
public System.Windows.Documents.TextPointer GetPositionAtOffset (int offset);
member this.GetPositionAtOffset : int -> System.Windows.Documents.TextPointer
Public Function GetPositionAtOffset (offset As Integer) As TextPointer

Paramètres

offset
Int32

Un offset, dans les symboles, pour lequel calculer et renvoyer la position. Si l'offset est négatif, la position est calculée dans la direction logique opposée de celle indiqué par la propriété LogicalDirection.

Retours

Un TextPointer à la position indiquée par le décalage spécifié, ou null si aucune position correspondante n'est trouvée.

Exemples

L’exemple suivant illustre l’utilisation de cette méthode. L’exemple utilise la GetPositionAtOffset méthode pour implémenter une paire de méthodes, l’une pour calculer le décalage à une position spécifiée par rapport à un paragraphe d’hébergement et l’autre pour renvoyer un TextPointer à un décalage spécifié dans un paragraphe spécifié.

// Returns the offset for the specified position relative to any containing paragraph.
int GetOffsetRelativeToParagraph(TextPointer position)
{
    // Adjust the pointer to the closest forward insertion position, and look for any
    // containing paragraph.
    Paragraph paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph;

    // Some positions may be not within any Paragraph; 
    // this method returns an offset of -1 to indicate this condition.
    return (paragraph == null) ? -1 : paragraph.ContentStart.GetOffsetToPosition(position);
}

// Returns a TextPointer to a specified offset into a specified paragraph. 
TextPointer GetTextPointerRelativeToParagraph(Paragraph paragraph, int offsetRelativeToParagraph)
{
    // Verify that the specified offset falls within the specified paragraph.  If the offset is
    // past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
    // Otherwise, return a TextPointer to the specified offset in the specified paragraph.
    return (offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd)) 
        ? paragraph.ContentEnd : paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph);
}
' Returns the offset for the specified position relative to any containing paragraph.
Private Function GetOffsetRelativeToParagraph(ByVal position As TextPointer) As Integer
    ' Adjust the pointer to the closest forward insertion position, and look for any
    ' containing paragraph.
    Dim paragraph As Paragraph = (position.GetInsertionPosition(LogicalDirection.Forward)).Paragraph

    ' Some positions may be not within any Paragraph 
    ' this method returns an offset of -1 to indicate this condition.
    Return If((paragraph Is Nothing), -1, paragraph.ContentStart.GetOffsetToPosition(position))
End Function

' Returns a TextPointer to a specified offset into a specified paragraph. 
Private Function GetTextPointerRelativeToParagraph(ByVal paragraph As Paragraph, ByVal offsetRelativeToParagraph As Integer) As TextPointer
    ' Verify that the specified offset falls within the specified paragraph.  If the offset is
    ' past the end of the paragraph, return a pointer to the farthest offset position in the paragraph.
    ' Otherwise, return a TextPointer to the specified offset in the specified paragraph.
    Return If((offsetRelativeToParagraph > paragraph.ContentStart.GetOffsetToPosition(paragraph.ContentEnd)), paragraph.ContentEnd, paragraph.ContentStart.GetPositionAtOffset(offsetRelativeToParagraph))
End Function

Remarques

L’un des éléments suivants est considéré comme un symbole :

  • Balise ouvrante ou fermante pour l’élément TextElement .

  • Élément UIElement contenu dans un InlineUIContainer ou .BlockUIContainer Notez qu’un UIElement tel est toujours compté comme un seul symbole ; tout contenu ou élément supplémentaire contenu par le UIElement ne sont pas comptés comme symboles.

  • Caractère Unicode 16 bits à l’intérieur d’un élément de texte Run .

Voir aussi

S’applique à