다음을 통해 공유


RichTextBox.SelectionColor 속성

정의

현재 텍스트 선택 영역 또는 삽입 지점의 텍스트 색을 가져오거나 설정합니다.

public:
 property System::Drawing::Color SelectionColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Color SelectionColor { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionColor : System.Drawing.Color with get, set
Public Property SelectionColor As Color

속성 값

Color 현재 텍스트 선택 영역이나 삽입 지점 뒤에 입력한 텍스트에 적용할 색을 나타내는 값입니다.

특성

예제

다음 코드 예제에서는 현재 텍스트 선택 또는 컨트롤의 현재 삽입 지점 뒤에 입력 된 텍스트에 대 한 색을 지정 하는 사용자를 표시 ColorDialog 합니다 RichTextBox . 이 예제에서는 예제에 정의된 메서드를 명명richTextBox1된 컨트롤이 Form 포함된 클래스에 RichTextBox 추가해야 합니다.

public:
   void ChangeMySelectionColor()
   {
      ColorDialog^ colorDialog1 = gcnew ColorDialog;
      
      // Set the initial color of the dialog to the current text color.
      colorDialog1->Color = richTextBox1->SelectionColor;
      
      // Determine if the user clicked OK in the dialog and that the color has changed.
      if ( colorDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK &&
         colorDialog1->Color != richTextBox1->SelectionColor )
      {
         // Change the selection color to the user specified color.
         richTextBox1->SelectionColor = colorDialog1->Color;
      }
   }
public void ChangeMySelectionColor()
{
   ColorDialog colorDialog1 = new ColorDialog();

   // Set the initial color of the dialog to the current text color.
   colorDialog1.Color = richTextBox1.SelectionColor;

   // Determine if the user clicked OK in the dialog and that the color has changed.
   if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && 
      colorDialog1.Color != richTextBox1.SelectionColor)
   {
      // Change the selection color to the user specified color.
      richTextBox1.SelectionColor = colorDialog1.Color;
   }
}
Public Sub ChangeMySelectionColor()
    Dim colorDialog1 As New ColorDialog()
    
    ' Set the initial color of the dialog to the current text color.
    colorDialog1.Color = richTextBox1.SelectionColor
    
    ' Determine if the user clicked OK in the dialog and that the color has
    ' changed.
    If (colorDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
        And Not(colorDialog1.Color.Equals(richTextBox1.SelectionColor)) Then
        
        ' Change the selection color to the user specified color.
        richTextBox1.SelectionColor = colorDialog1.Color
    End If
End Sub

설명

현재 텍스트 선택 영역에 둘 이상의 색이 지정되어 있으면 이 속성이 반환됩니다 Color.Empty. 현재 선택된 텍스트가 없으면 이 속성에 지정된 텍스트 색이 현재 삽입 지점 및 삽입 지점 뒤에 컨트롤에 입력된 모든 텍스트에 적용됩니다. 텍스트 색 설정은 속성이 다른 색으로 변경되거나 삽입 포인터가 컨트롤 내의 다른 섹션으로 이동할 때까지 적용됩니다.

컨트롤 내에서 텍스트를 선택하면 선택한 텍스트와 텍스트 선택 뒤에 입력된 모든 텍스트에 이 속성의 값이 적용됩니다. 이 속성을 사용하여 텍스트 색을 변경할 수 있습니다 RichTextBox.

컨트롤에서 텍스트를 굵게 만들려면 속성을 사용하여 SelectionFont 굵은 글꼴 스타일이 지정된 새 글꼴을 할당합니다.

적용 대상

추가 정보