TextPointer.GetPositionAtOffset 메서드

정의

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

오버로드

Name Description
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 지정된 오프셋으로 표시된 위치 또는 null 오프셋이 콘텐츠의 끝을 지나 확장되는 경우의 A입니다.

설명

다음 중 하나는 기호로 간주됩니다.

  • 요소에 대한 여는 태그 또는 닫는 태그입니다 TextElement .

  • UIElement 또는 InlineUIContainerBlockUIContainer 포함된 요소입니다. 이러한 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 지정된 오프셋으로 표시된 위치 또는 null 해당 위치를 찾을 수 없는 경우의 A입니다.

예제

다음 예제에서는이 메서드에 대 한 사용을 보여 줍니다. 이 예제에서는 메서드를 사용하여 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 .

  • UIElement 또는 InlineUIContainerBlockUIContainer 포함된 요소입니다. 이러한 UIElement 항상 정확히 하나의 기호로 계산됩니다. UIElement 포함된 추가 콘텐츠 또는 요소는 기호로 계산되지 않습니다.

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

추가 정보

적용 대상