TextPointer.GetPositionAtOffset Metode

Definisi

Mengembalikan ke posisi yang TextPointer ditunjukkan oleh offset yang ditentukan, dalam simbol, dari awal konten.

Overload

Nama Deskripsi
GetPositionAtOffset(Int32, LogicalDirection)

Mengembalikan ke posisi yang TextPointer ditunjukkan oleh offset yang ditentukan, dalam simbol, dari awal saat ini TextPointer dan dalam arah yang ditentukan.

GetPositionAtOffset(Int32)

Mengembalikan ke posisi yang TextPointer ditunjukkan oleh offset yang ditentukan, dalam simbol, dari awal saat ini TextPointer.

GetPositionAtOffset(Int32, LogicalDirection)

Mengembalikan ke posisi yang TextPointer ditunjukkan oleh offset yang ditentukan, dalam simbol, dari awal saat ini TextPointer dan dalam arah yang ditentukan.

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

Parameter

offset
Int32

Offset, dalam simbol, untuk menghitung dan mengembalikan posisi. Jika offset negatif, yang dikembalikan mendahului TextPointer saat ini TextPointer; jika tidak, itu mengikuti.

direction
LogicalDirection

Salah LogicalDirection satu nilai yang menentukan arah logis dari yang dikembalikan TextPointer.

Mengembalikan

TextPointer ke posisi yang ditunjukkan oleh offset yang ditentukan, atau null jika offset meluas melewati akhir konten.

Keterangan

Salah satu hal berikut dianggap sebagai simbol:

Lihat juga

Berlaku untuk

GetPositionAtOffset(Int32)

Mengembalikan ke posisi yang TextPointer ditunjukkan oleh offset yang ditentukan, dalam simbol, dari awal saat ini 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

Parameter

offset
Int32

Offset, dalam simbol, untuk menghitung dan mengembalikan posisi. Jika offset negatif, posisi dihitung ke arah logis yang berlawanan dengan yang ditunjukkan oleh LogicalDirection properti .

Mengembalikan

TextPointer ke posisi yang ditunjukkan oleh offset yang ditentukan, atau null jika tidak ada posisi yang sesuai yang dapat ditemukan.

Contoh

Contoh berikut menunjukkan penggunaan untuk metode ini. Contoh menggunakan GetPositionAtOffset metode untuk mengimplementasikan sepasang metode, satu untuk menghitung offset ke posisi tertentu yang relatif terhadap paragraf hosting apa pun, dan yang lain untuk mengembalikan TextPointer ke offset tertentu dalam paragraf tertentu.

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

Keterangan

Salah satu hal berikut dianggap sebagai simbol:

Lihat juga

Berlaku untuk