Aracılığıyla paylaş


TextRange(TextPointer, TextPointer) Oluşturucu

Tanım

Yeni aralığın TextRange başlangıç ve bitiş konumları olarak belirtilen TextPointer iki konumu alarak sınıfının yeni bir örneğini başlatır.

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)

Parametreler

position1
TextPointer

Yeni TextRangeöğesini oluşturmak için kullanılan seçimin bir ucunu işaretleyen sabit yer işareti konumu.

position2
TextPointer

Yeni TextRangeöğesini oluşturmak için kullanılan seçimin diğer ucunu işaretleyen taşınabilir bir konum.

Özel durumlar

ve position2 aynı belge içinde konumlandırılmadığında position1 gerçekleşir.

veya position2 olduğunda position1 nullgerçekleşir.

Örnekler

Aşağıdaki örnekte oluşturucunun kullanımı gösterilmektedir 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çıklamalar

A TextRange , TextPointers tarafından belirtilen iki konum arasındaki seçimden oluşturulur. Bu konumlardan biri (ile position1gösterilir) seçime göre sabitken, diğer konum (ile position2gösterilir) taşınabilir. Bu, kullanıcının fare veya klavye kullanarak yaptığı seçimin davranışına benzer.

Yeninin gerçek uçları, yeni TextRange TextRangeöğesini içeren belge için geçerli olan seçim buluşsal yöntemleriyle eşleşecek şekilde ayarlanabilir.

Şunlara uygulanır