TextPointer.GetOffsetToPosition(TextPointer) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 TextPointer와 지정된 두 번째 TextPointer 사이의 기호 수를 반환합니다.
public:
int GetOffsetToPosition(System::Windows::Documents::TextPointer ^ position);
public int GetOffsetToPosition(System.Windows.Documents.TextPointer position);
member this.GetOffsetToPosition : System.Windows.Documents.TextPointer -> int
Public Function GetOffsetToPosition (position As TextPointer) As Integer
매개 변수
- position
- TextPointer
거리(기호)를 찾을 위치를 지정하는 TextPointer입니다.
반환
현재 TextPointer와 position 사이의 상대적 기호 수입니다. 음수 값은 현재 TextPointer가 position에 지정된 위치 뒤에 옴을 나타내고, 0은 위치가 동일함을 나타내고, 양수 값은 현재 TextPointer가 position에 지정된 위치 앞에 옴을 나타냅니다.
예외
position이 현재 위치와 연결된 텍스트 컨테이너의 외부 위치를 지정하는 경우
예제
다음 예제는이 메서드의 사용 방법을 보여 줍니다. 예제에서는 합니다 GetOffsetToPosition 2에 대 한 오프셋을 확인 하는 방법 TextPointer 인스턴스와 다음이 정보를 사용 하 여 저장 하 고 선택 영역 복원를 RichTextBox합니다. 가정 내용을 RichTextBox 저장 선택 및 선택 영역 복원 간에 변경 되지 않았습니다.
struct SelectionOffsets { internal int Start; internal int End; }
SelectionOffsets GetSelectionOffsetsRTB(RichTextBox richTextBox)
{
SelectionOffsets selectionOffsets;
TextPointer contentStart = richTextBox.Document.ContentStart;
// Find the offset for the starting and ending TextPointers.
selectionOffsets.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start);
selectionOffsets.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End);
return selectionOffsets;
}
void RestoreSelectionOffsetsRTB(RichTextBox richTextBox, SelectionOffsets selectionOffsets)
{
TextPointer contentStart = richTextBox.Document.ContentStart;
// Use previously determined offsets to create corresponding TextPointers,
// and use these to restore the selection.
richTextBox.Selection.Select(
contentStart.GetPositionAtOffset(selectionOffsets.Start),
contentStart.GetPositionAtOffset(selectionOffsets.End)
);
}
Private Structure SelectionOffsets
Friend Start As Integer
Friend [End] As Integer
End Structure
Private Function GetSelectionOffsetsRTB(ByVal richTextBox As RichTextBox) As SelectionOffsets
Dim selectionOffsets As SelectionOffsets
Dim contentStart As TextPointer = richTextBox.Document.ContentStart
' Find the offset for the starting and ending TextPointers.
selectionOffsets.Start = contentStart.GetOffsetToPosition(richTextBox.Selection.Start)
selectionOffsets.End = contentStart.GetOffsetToPosition(richTextBox.Selection.End)
Return selectionOffsets
End Function
Private Sub RestoreSelectionOffsetsRTB(ByVal richTextBox As RichTextBox, ByVal selectionOffsets As SelectionOffsets)
Dim contentStart As TextPointer = richTextBox.Document.ContentStart
' Use previously determined offsets to create corresponding TextPointers,
' and use these to restore the selection.
richTextBox.Selection.Select(contentStart.GetPositionAtOffset(selectionOffsets.Start), contentStart.GetPositionAtOffset(selectionOffsets.End))
End Sub
설명
다음 항목은 기호 간주 됩니다.
여는 태그 또는 닫는 태그가 TextElement 요소입니다.
A UIElement 에 포함 된 요소를 InlineUIContainer 또는 BlockUIContainer합니다. 즉, 이러한 참고는 UIElement 은 항상 하나만 기호; 모든 추가 콘텐츠 또는 요소에 포함 된 계산는 UIElement 기호로 계산 되지 않습니다.
텍스트 Run 요소 내의 16비트 유니코드 문자입니다.