RichTextBox.SelectionLength Свойство

Определение

Возвращает или задает количество символов, выбранных в элементе управления.

public:
 virtual property int SelectionLength { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public override int SelectionLength { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionLength : int with get, set
Public Overrides Property SelectionLength As Integer

Значение свойства

Число символов, выбранных в текстовом поле.

Атрибуты

Примеры

В следующем примере кода показано, как использовать SelectionLength свойство для определения того, выбран ли текст в пределах.RichTextBox В этом примере требуется, чтобы RichTextBox элемент управления с именем richTextBox1был добавлен в форму. В примере также требуется, чтобы richTextBox1 он содержал текст, выбранный в элементе управления.

private:
   void ModifySelectedText()
   {
      // Determine if text is selected in the control.
      if ( richTextBox1->SelectionLength > 0 )
      {
         // Set the color of the selected text in the control.
         richTextBox1->SelectionColor = Color::Red;

         // Set the font of the selected text to bold and underlined.
         richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",10,static_cast<FontStyle>(FontStyle::Bold | FontStyle::Underline) );

         // Protect the selected text from modification.
         richTextBox1->SelectionProtected = true;
      }
   }
private void ModifySelectedText()
{
   // Determine if text is selected in the control.
   if (richTextBox1.SelectionLength > 0)
   {
      // Set the color of the selected text in the control.
      richTextBox1.SelectionColor = Color.Red;
      // Set the font of the selected text to bold and underlined.
      richTextBox1.SelectionFont = new Font("Arial",10,FontStyle.Bold | FontStyle.Underline);
      // Protect the selected text from modification.
      richTextBox1.SelectionProtected = true;
   }
}
Private Sub ModifySelectedText()
    ' Determine if text is selected in the control.
    If (richTextBox1.SelectionLength > 0) Then
        ' Set the color of the selected text in the control.
        richTextBox1.SelectionColor = Color.Red
        ' Set the font of the selected text to bold and underlined.
        richTextBox1.SelectionFont = New Font("Arial", 10, FontStyle.Bold Or FontStyle.Underline)
        ' Protect the selected text from modification.
        richTextBox1.SelectionProtected = True
    End If
End Sub

Комментарии

Это свойство можно использовать для определения того, выбраны ли какие-либо символы в элементе управления текстового поля перед выполнением операций с выделенным текстом. Это свойство также можно использовать для определения общего количества символов (включая пробелы), выбранных при выполнении однозначных задач в цикле for .

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

См. также раздел