다음을 통해 공유


TextRange(TextPointer, TextPointer) 생성자

정의

지정된 두 TextRange 위치를 새 범위의 시작 위치와 끝 위치로 사용하여 TextPointer 클래스의 새 인스턴스를 초기화합니다.

public:
 TextRange(System::Windows::Documents::TextPointer ^ position1, System::Windows::Documents::TextPointer ^ position2);
public TextRange (System.Windows.Documents.TextPointer position1, System.Windows.Documents.TextPointer position2);
new System.Windows.Documents.TextRange : System.Windows.Documents.TextPointer * System.Windows.Documents.TextPointer -> System.Windows.Documents.TextRange
Public Sub New (position1 As TextPointer, position2 As TextPointer)

매개 변수

position1
TextPointer

TextRange를 구성하는 데 사용되는 선택 영역의 한쪽 끝을 표시하는 고정된 앵커 위치입니다.

position2
TextPointer

TextRange를 구성하는 데 사용되는 선택 영역의 다른 쪽 끝을 표시하는 이동 가능한 위치입니다.

예외

position1position2가 동일한 문서 내에 있지 않은 경우 발생합니다.

position1 또는 position2null인 경우 발생합니다.

예제

다음 예제에서는 사용 된 TextRange 생성자입니다.

// This method returns a plain text representation of a specified FlowDocument.
string GetTextFromFlowDocument(FlowDocument flowDoc)
{
     // Create a new TextRanage that takes the entire FlowDocument as the current selection.
     TextRange flowDocSelection = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);
      
     // Use the Text property to extract a string that contains the unformatted text contents 
     // of the FlowDocument.
     return flowDocSelection.Text;
}
' This method returns a plain text representation of a specified FlowDocument.
Private Function GetTextFromFlowDocument(ByVal flowDoc As FlowDocument) As String
    ' Create a new TextRanage that takes the entire FlowDocument as the current selection.
    Dim flowDocSelection As New TextRange(flowDoc.ContentStart, flowDoc.ContentEnd)

    ' Use the Text property to extract a string that contains the unformatted text contents 
    ' of the FlowDocument.
    Return flowDocSelection.Text
End Function

설명

A TextRange 선택 항목으로 표시 하는 두 위치 사이 형식이 TextPointers 합니다. 이러한 위치 중 하나 (나타난 position1) 다른 위치 선택 항목을 기준으로 고정 되 (나타난 position2) 이동할 수 있습니다. 마우스나 키보드를 사용 하 여 사용자가 선택한 동작 방식을 하는 것과 비슷합니다.

새 실제 끝 TextRange 새 포함 하는 문서에 적용할 수 있는 모든 선택 추론에 맞게 조정 될 수 있습니다 TextRange합니다.

적용 대상