共用方式為


RichTextBox.Selection 屬性

定義

取得 TextSelection 物件,這個物件包含 RichTextBox 中的目前選取項目。

public:
 property System::Windows::Documents::TextSelection ^ Selection { System::Windows::Documents::TextSelection ^ get(); };
public System.Windows.Documents.TextSelection Selection { get; }
member this.Selection : System.Windows.Documents.TextSelection
Public ReadOnly Property Selection As TextSelection

屬性值

TextSelection

TextSelection 物件,包含 RichTextBox 中的目前選取項目。

預設所傳回 TextSelectionIsEmpty 屬性值為 true。 在未選取項目的文字區域中,空的 TextSelection 會呈現為插入號。

範例

下列範例說明此屬性的使用。

// Create a simple FlowDocument to serve as the content input for the construtor.
FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("Simple FlowDocument")));
// After this constructor is called, the new RichTextBox rtb will contain flowDoc.
RichTextBox rtb = new RichTextBox(flowDoc);
// This call will select the entire contents of the RichTextBox.
rtb.SelectAll();
// This call returns the current selection (which happens to be the entire contents
// of the RichTextBox) as a TextSelection object.
TextSelection currentSelection = rtb.Selection;
' Create a simple FlowDocument to serve as the content input for the construtor.
Dim flowDoc As New FlowDocument(New Paragraph(New Run("Simple FlowDocument")))
' After this constructor is called, the new RichTextBox rtb will contain flowDoc.
Dim rtb As New RichTextBox(flowDoc)
' This call will select the entire contents of the RichTextBox.
rtb.SelectAll()
' This call returns the current selection (which happens to be the entire contents
' of the RichTextBox) as a TextSelection object.
Dim currentSelection As TextSelection = rtb.Selection

備註

Select使用 方法來以程式設計方式選取內容。

適用於