Share via


TextRange.Text プロパティ

定義

現在の選択範囲のプレーン テキスト コンテンツを取得または設定します。

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

プロパティ値

現在の選択範囲のプレーン テキスト コンテンツを含む文字列。

例外

このプロパティを null に設定しようとすると発生します。

次の例では、 プロパティの使用方法を Text 示します。

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

注釈

このプロパティを使用すると、存在する可能性のある書式設定に関係なく、現在の選択範囲のプレーン テキスト コンテンツを抽出できます。

新しい行文字と段落区切りは、このプロパティに対して同等として扱われます。 現在の選択範囲に存在するすべての種類のコンテンツ区切りは、このプロパティの読み取り時に新しい行に変換されます。

適用対象