RichTextBox.Selection RichTextBox.Selection RichTextBox.Selection RichTextBox.Selection Property

Определение

Получает объект TextSelection, содержащий текущий выделенный фрагмент элемента RichTextBox.Gets a TextSelection object containing the current selection in the 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, содержащий текущий выделенный фрагмент элемента RichTextBox.A TextSelection object containing the current selection in the RichTextBox.

У возвращаемого по умолчанию объекта TextSelection свойство IsEmpty имеет значение true.The default returned TextSelection has an IsEmpty property value of true. Пустой объект TextSelection изображается в виде символа вставки в текстовой области без выделения.An empty TextSelection renders as a caret in the text area with no selection.

Примеры

В следующем примере показано использование этого свойства.The following example illustrates the use of this property.

// 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 Используйте метод для программного выбора содержимого.Use the Select method to programmatically select content.

Применяется к