Share via


TextPointer.GetPositionAtOffset 메서드

정의

콘텐츠 시작 부분에서 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

오버로드

GetPositionAtOffset(Int32, LogicalDirection)

현재 TextPointer의 시작 부분에서 지정된 방향으로 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

GetPositionAtOffset(Int32)

현재 TextPointer 시작 부분에서 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

GetPositionAtOffset(Int32, LogicalDirection)

현재 TextPointer의 시작 부분에서 지정된 방향으로 지정된 오프셋(기호)으로 표시되는 위치에 대한 TextPointer를 반환합니다.

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

매개 변수

offset
Int32

위치를 계산하고 반환할 오프셋(기호)입니다. 오프셋이 음수이면 반환되는 TextPointer는 현재 TextPointer 앞에 오고, 그렇지 않으면 뒤에 옵니다.

direction
LogicalDirection

반환되는 LogicalDirection의 논리 방향을 지정하는 TextPointer 값 중 하나입니다.

반환

TextPointer

지정된 오프셋으로 표시되는 위치에 대한 TextPointer입니다. 오프셋이 콘텐츠 끝을 지나 확장되는 경우 null입니다.

설명

다음 항목은 기호 간주 됩니다.

  • 여는 태그 또는 닫는 태그가 TextElement 요소입니다.

  • A UIElement 에 포함 된 요소를 InlineUIContainer 또는 BlockUIContainer합니다. 즉, 이러한 참고는 UIElement 은 항상 하나만 기호; 모든 추가 콘텐츠 또는 요소에 포함 된 계산는 UIElement 기호로 계산 되지 않습니다.

  • 텍스트 Run 요소 내의 16비트 유니코드 문자입니다.

추가 정보

적용 대상

GetPositionAtOffset(Int32)

현재 TextPointer 시작 부분에서 지정된 오프셋(기호)으로 표시되는 위치에 대한 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

매개 변수

offset
Int32

위치를 계산하고 반환할 오프셋(기호)입니다. 오프셋이 음수이면 위치는 LogicalDirection 속성으로 표시되는 방향과 반대 논리 방향으로 계산됩니다.

반환

TextPointer

지정된 오프셋으로 표시되는 위치에 대한 TextPointer입니다. 해당 위치를 찾을 수 없는 경우 null입니다.

예제

다음 예제는이 메서드의 사용 방법을 보여 줍니다. 예제에서는 합니다 GetPositionAtOffset 쌍의 모든 호스팅 단락 및 반환할 다른에 비해 지정된 된 위치에 대 한 오프셋을 계산 하는 메서드를 구현 하는 방법을 TextPointer 지정된 단락에 지정 된 오프셋에 합니다.

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

설명

다음 항목은 기호 간주 됩니다.

  • 여는 태그 또는 닫는 태그가 TextElement 요소입니다.

  • A UIElement 에 포함 된 요소를 InlineUIContainer 또는 BlockUIContainer합니다. 즉, 이러한 참고는 UIElement 은 항상 하나만 기호; 모든 추가 콘텐츠 또는 요소에 포함 된 계산는 UIElement 기호로 계산 되지 않습니다.

  • 텍스트 Run 요소 내의 16비트 유니코드 문자입니다.

추가 정보

적용 대상