Udostępnij przez


TextPointer.GetPositionAtOffset Metoda

Definicja

Zwraca wartość typu TextPointer do pozycji wskazanej przez określone przesunięcie w symbolach od początku zawartości.

Przeciążenia

GetPositionAtOffset(Int32, LogicalDirection)

Zwraca wartość typu TextPointer do pozycji wskazanej przez określone przesunięcie w symbolach od początku bieżącego TextPointer i w określonym kierunku.

GetPositionAtOffset(Int32)

Zwraca wartość typu TextPointer do pozycji wskazanej przez określone przesunięcie w symbolach od początku bieżącego TextPointerelementu .

GetPositionAtOffset(Int32, LogicalDirection)

Zwraca wartość typu TextPointer do pozycji wskazanej przez określone przesunięcie w symbolach od początku bieżącego TextPointer i w określonym kierunku.

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

Parametry

offset
Int32

Przesunięcie w symbolach, dla których ma być obliczane i zwracane położenie. Jeśli przesunięcie jest ujemne, zwrócony TextPointer poprzedza bieżący TextPointer; w przeciwnym razie następuje.

direction
LogicalDirection

LogicalDirection Jedna z wartości określających logiczny kierunek zwracanego TextPointerelementu .

Zwraca

A TextPointer do pozycji wskazanej przez określone przesunięcie lub null jeśli przesunięcie rozciąga się poza koniec zawartości.

Uwagi

Każdy z poniższych elementów jest uważany za symbol:

  • Tag otwierający lub zamykający TextElement dla elementu.

  • Element UIElement zawarty w elemecie InlineUIContainer lub BlockUIContainer. Należy pamiętać, że taki element UIElement jest zawsze liczone jako dokładnie jeden symbol. Każda dodatkowa zawartość lub elementy zawarte w obiekcie UIElement nie są liczone jako symbole.

  • 16-bitowy znak Unicode wewnątrz elementu tekstowego Run .

Zobacz też

Dotyczy

GetPositionAtOffset(Int32)

Zwraca wartość typu TextPointer do pozycji wskazanej przez określone przesunięcie w symbolach od początku bieżącego TextPointerelementu .

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

Parametry

offset
Int32

Przesunięcie w symbolach, dla których ma być obliczane i zwracane położenie. Jeśli przesunięcie jest ujemne, pozycja jest obliczana w kierunku logicznym odwrotnym od tego wskazanego LogicalDirection przez właściwość .

Zwraca

A TextPointer do pozycji wskazanej przez określone przesunięcie lub null jeśli nie można odnaleźć odpowiedniego położenia.

Przykłady

W poniższym przykładzie pokazano użycie tej metody. W przykładzie użyto GetPositionAtOffset metody , aby zaimplementować parę metod, jeden do obliczenia przesunięcia na określoną pozycję względem dowolnego akapitu hostingu, a drugi do zwrócenia TextPointer do określonego przesunięcia w określonym akapicie.

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

Uwagi

Każdy z poniższych elementów jest uważany za symbol:

  • Tag otwierający lub zamykający TextElement dla elementu.

  • Element UIElement zawarty w elemecie InlineUIContainer lub BlockUIContainer. Należy pamiętać, że taki element UIElement jest zawsze liczone jako dokładnie jeden symbol. Każda dodatkowa zawartość lub elementy zawarte w obiekcie UIElement nie są liczone jako symbole.

  • 16-bitowy znak Unicode wewnątrz elementu tekstowego Run .

Zobacz też

Dotyczy