TextPointer.GetPositionAtOffset Método

Definición

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del contenido.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of content.

Sobrecargas

GetPositionAtOffset(Int32, LogicalDirection)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual y en la dirección especificada.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer and in the specified direction.

GetPositionAtOffset(Int32)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer.

GetPositionAtOffset(Int32, LogicalDirection)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual y en la dirección especificada.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer and in the specified direction.

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

Un desplazamiento, en símbolos, para el que calcular y devolver la posición.An offset, in symbols, for which to calculate and return the position. Si el desplazamiento es negativo, el TextPointer devuelto precede al TextPointer actual; de lo contrario, le sigue.If the offset is negative, the returned TextPointer precedes the current TextPointer; otherwise, it follows.

direction
LogicalDirection

Uno de los valores de LogicalDirection que especifica la dirección lógica del TextPointer devuelto.One of the LogicalDirection values that specifies the logical direction of the returned TextPointer.

Devoluciones

TextPointer

TextPointer a la posición indicada por el desplazamiento especificado o null si el desplazamiento se extiende más allá del final del contenido.A TextPointer to the position indicated by the specified offset, or null if the offset extends past the end of the content.

Comentarios

Cualquiera de los siguientes elementos se considera un símbolo:Any of the following is considered to be a symbol:

Consulte también

Se aplica a

GetPositionAtOffset(Int32)

Devuelve TextPointer a la posición indicada por el desplazamiento especificado, en símbolos, a partir del principio del TextPointer actual.Returns a TextPointer to the position indicated by the specified offset, in symbols, from the beginning of the current TextPointer.

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

Un desplazamiento, en símbolos, para el que calcular y devolver la posición.An offset, in symbols, for which to calculate and return the position. Si el desplazamiento es negativo, la posición se calcula en la dirección lógica contraria a la indicada por la propiedad LogicalDirection.If the offset is negative, the position is calculated in the logical direction opposite of that indicated by the LogicalDirection property.

Devoluciones

TextPointer

TextPointer a la posición indicada por el desplazamiento especificado o null si no se encuentra ninguna posición correspondiente.A TextPointer to the position indicated by the specified offset, or null if no corresponding position can be found.

Ejemplos

En el ejemplo siguiente se muestra un uso para este método.The following example demonstrates a use for this method. En el ejemplo se usa el GetPositionAtOffset método para implementar un par de métodos, uno para calcular el desplazamiento en una posición especificada relativa a cualquier párrafo de hospedaje, y el otro para devolver un valor TextPointer a un desplazamiento especificado en un párrafo especificado.The example uses the GetPositionAtOffset method to implement a pair of methods, one to calculate the offset to a specified position relative to any hosting paragraph, and the other to return a TextPointer to a specified offset in a specified paragraph.

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

Comentarios

Cualquiera de los siguientes elementos se considera un símbolo:Any of the following is considered to be a symbol:

Consulte también

Se aplica a