Share via


TextPointer.GetPositionAtOffset Método

Definição

Retorna um TextPointer à posição indicada pelo deslocamento especificado, em símbolos, do início do conteúdo.

Sobrecargas

GetPositionAtOffset(Int32, LogicalDirection)

Retorna um TextPointer à posição indicada pelo deslocamento especificado nos símbolos, desde o início do TextPointer atual e na direção especificada.

GetPositionAtOffset(Int32)

Retorna um TextPointer à posição indicada pelo deslocamento especificado nos símbolos, desde o início do TextPointer atual.

GetPositionAtOffset(Int32, LogicalDirection)

Retorna um TextPointer à posição indicada pelo deslocamento especificado nos símbolos, desde o início do TextPointer atual e na direção especificada.

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

Parâmetros

offset
Int32

Um deslocamento, em símbolos, para o qual calcular e retornar a posição. Se o deslocamento for negativo, o TextPointer retornado precede o atual TextPointer, caso contrário, ele sucede.

direction
LogicalDirection

Um dos valores LogicalDirection que especifica a direção da lógica do TextPointer retornado.

Retornos

TextPointer

Um TextPointer para a posição indicada pelo deslocamento especificado ou null se o deslocamento ultrapassar o fim do conteúdo.

Comentários

Qualquer um dos seguintes é considerado um símbolo:

  • Uma marca de abertura ou fechamento para o TextElement elemento.

  • Um UIElement elemento contido em um InlineUIContainer ou BlockUIContainer. Observe que esse UIElement tipo sempre é contado como exatamente um símbolo; qualquer conteúdo adicional ou elementos contidos pelo UIElement não são contados como símbolos.

  • Um caractere Unicode de 16 bits dentro de um elemento de texto Run .

Confira também

Aplica-se a

GetPositionAtOffset(Int32)

Retorna um TextPointer à posição indicada pelo deslocamento especificado nos símbolos, desde o início do TextPointer atual.

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

Parâmetros

offset
Int32

Um deslocamento, em símbolos, para o qual calcular e retornar a posição. Se o deslocamento for negativo, a posição será calculada na direção lógica oposta àquela indicada pela propriedade LogicalDirection.

Retornos

TextPointer

Um TextPointer para a posição indicada pelo deslocamento especificado ou null se nenhuma posição correspondente puder ser encontrada.

Exemplos

O exemplo a seguir demonstra um uso para este método. O exemplo usa o GetPositionAtOffset método para implementar um par de métodos, um para calcular o deslocamento para uma posição especificada em relação a qualquer parágrafo de hospedagem e o outro para retornar um a um TextPointer deslocamento especificado em um parágrafo especificado.

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

Comentários

Qualquer um dos seguintes é considerado um símbolo:

  • Uma marca de abertura ou fechamento para o TextElement elemento.

  • Um UIElement elemento contido em um InlineUIContainer ou BlockUIContainer. Observe que esse UIElement tipo sempre é contado como exatamente um símbolo; qualquer conteúdo adicional ou elementos contidos pelo UIElement não são contados como símbolos.

  • Um caractere Unicode de 16 bits dentro de um elemento de texto Run .

Confira também

Aplica-se a