共用方式為


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

屬性值

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

備註

使用此屬性來擷取目前選取範圍中的純文字內容,不論是否有任何可能的格式。

新的分行符號和段落分隔符號會被視為與這個屬性相等的。 讀取此屬性時,目前選取範圍中存在的任何類型的內容中斷都會轉換成新行。

適用於