TextRange(TextPointer, TextPointer) Konstruktor

Definition

Initierar en ny instans av TextRange klassen och tar två angivna TextPointer positioner som start- och slutpositioner för det nya intervallet.

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)

Parametrar

position1
TextPointer

En fast fästpunkt som markerar ena änden av markeringen som används för att bilda den nya TextRange.

position2
TextPointer

En flyttbar position som markerar den andra änden av markeringen som används för att bilda den nya TextRange.

Undantag

Inträffar när position1 och position2 inte är placerade i samma dokument.

Inträffar när position1 eller position2 är null.

Exempel

I följande exempel visas hur konstruktorn används 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

Kommentarer

A TextRange bildas från en markering mellan två positioner som anges av TextPointers. En av dessa positioner (anges av position1) är fast med avseende på valet, medan den andra positionen (anges av position2) är rörlig. Detta liknar hur ett val som görs av en användare med hjälp av musen eller tangentbordet fungerar.

De faktiska ändarna av den nya TextRange kan justeras så att de matchar val-heuristik som gäller för dokumentet som innehåller det nya TextRange.

Gäller för