Share via


TextRange(TextPointer, TextPointer) コンストラクター

定義

新しい範囲の開始位置および終了位置として指定された 2 つの 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 によって示される 2 つの位置の選択から形成されます。 これらの位置 (によって position1示される) の 1 つが選択に対して固定され、もう一方の位置 (によって position2示される) は移動可能です。 これは、マウスまたはキーボードを使用してユーザーが選択した動作に似ています。

新しい文書を含むドキュメントに適用できる選択ヒューリスティックと一致するように、新規TextRangeTextRangeの実際の末尾を調整できます。

適用対象