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

속성 값

Int32

텍스트 상자에서 선택한 문자 수입니다.

특성

예제

다음 코드 예제에서는 속성을 사용 하 여 SelectionLength 텍스트 내에서 RichTextBox선택 되어 있는지 여부를 확인 하는 방법을 보여 줍니다. 이 예제에서는 명명richTextBox1RichTextBox 컨트롤이 양식에 추가되어야 합니다. 이 예제에서는 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 수행할 때 선택한 총 문자 수(공백 포함)를 결정하는 데 이 속성을 사용할 수도 있습니다.

적용 대상

추가 정보