TextRange(TextPointer, TextPointer) Konstruktor

Definisi

Menginisialisasi instans baru kelas TextRange, mengambil dua posisi TextPointer yang ditentukan sebagai posisi awal dan akhir untuk rentang baru.

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)

Parameter

position1
TextPointer

Posisi jangkar tetap yang menandai salah satu ujung pilihan yang digunakan untuk membentuk yang baru TextRange.

position2
TextPointer

Posisi movable yang menandai ujung lain dari pilihan yang digunakan untuk membentuk yang baru TextRange.

Pengecualian

Terjadi ketika position1 dan position2 tidak diposisikan dalam dokumen yang sama.

Terjadi ketika position1 atau position2 adalah null.

Contoh

Contoh berikut menunjukkan penggunaan TextRange konstruktor.

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

Keterangan

TextRange dibentuk dari pilihan antara dua posisi yang ditunjukkan oleh TextPointers. Salah satu posisi ini (ditunjukkan oleh position1) diperbaiki sehubungan dengan pilihan, sementara posisi lainnya (ditunjukkan oleh position2) dapat bergerak. Ini mirip dengan bagaimana pilihan yang dibuat oleh pengguna menggunakan mouse atau keyboard berulah.

Akhir aktual dari yang baru TextRange dapat disesuaikan untuk mencocokkan heuristik pilihan apa pun yang berlaku untuk dokumen yang berisi baru TextRange.

Berlaku untuk