TextPointer.GetPositionAtOffset Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve a TextPointer à posição indicada pelo deslocamento especificado, em símbolos, desde o início do conteúdo.
Sobrecargas
| Name | Description |
|---|---|
| GetPositionAtOffset(Int32, LogicalDirection) |
Devolve a TextPointer à posição indicada pelo deslocamento especificado, em símbolos, desde o início da corrente TextPointer e na direção especificada. |
| GetPositionAtOffset(Int32) |
Devolve a TextPointer à posição indicada pelo deslocamento especificado, em símbolos, a partir do início da corrente TextPointer. |
GetPositionAtOffset(Int32, LogicalDirection)
Devolve a TextPointer à posição indicada pelo deslocamento especificado, em símbolos, desde o início da corrente TextPointer 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 devolver a posição. Se o deslocamento for negativo, o retorno TextPointer precede a corrente TextPointer; caso contrário, segue-se.
- direction
- LogicalDirection
Um dos LogicalDirection valores que especifica a direção lógica do retorno TextPointer.
Devoluções
A TextPointer para a posição indicada pelo deslocamento especificado, ou null se o deslocamento se estender para além do final do conteúdo.
Observações
Qualquer um dos seguintes elementos é considerado um símbolo:
Uma etiqueta de abertura ou fecho para o TextElement elemento.
Um UIElement elemento contido num InlineUIContainer ou BlockUIContainer. Note-se que tal é UIElement sempre contado como exatamente um símbolo; qualquer conteúdo adicional ou elemento contido por o UIElement não é contado como símbolos.
Um carácter Unicode de 16 bits dentro de um elemento de texto Run .
Ver também
Aplica-se a
GetPositionAtOffset(Int32)
Devolve a TextPointer à posição indicada pelo deslocamento especificado, em símbolos, a partir do início da corrente 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
Um deslocamento, em símbolos, para o qual calcular e devolver a posição. Se o deslocamento for negativo, a posição é calculada na direção lógica oposta à indicada pela LogicalDirection propriedade.
Devoluções
A TextPointer para a posição indicada pelo deslocamento especificado, ou null se não for possível encontrar uma posição correspondente.
Exemplos
O exemplo seguinte demonstra a utilização deste método. O exemplo utiliza 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 acolhimento, e outro para devolver a TextPointer a a um deslocamento especificado num 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
Observações
Qualquer um dos seguintes elementos é considerado um símbolo:
Uma etiqueta de abertura ou fecho para o TextElement elemento.
Um UIElement elemento contido num InlineUIContainer ou BlockUIContainer. Note-se que tal é UIElement sempre contado como exatamente um símbolo; qualquer conteúdo adicional ou elemento contido por o UIElement não é contado como símbolos.
Um carácter Unicode de 16 bits dentro de um elemento de texto Run .