다음을 통해 공유


RichTextBox.SelectionColor 속성

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

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Property SelectionColor As Color
‘사용 방법
Dim instance As RichTextBox
Dim value As Color

value = instance.SelectionColor

instance.SelectionColor = value
public Color SelectionColor { get; set; }
public:
property Color SelectionColor {
    Color get ();
    void set (Color value);
}
/** @property */
public Color get_SelectionColor ()

/** @property */
public void set_SelectionColor (Color value)
public function get SelectionColor () : Color

public function set SelectionColor (value : Color)

속성 값

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

설명

현재의 텍스트 선택 영역에 색이 두 개 이상 지정되어 있으면 이 속성은 Color.Empty를 반환합니다. 선택된 텍스트가 없으면 현재 삽입 지점과 삽입 지점 다음에 입력된 컨트롤의 모든 텍스트에 대해 이 속성의 지정된 텍스트 색이 적용됩니다. 해당 속성이 다른 색으로 변경되거나 삽입 지점이 컨트롤 내의 다른 부분으로 이동할 때까지 텍스트 색 설정이 적용됩니다.

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

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

예제

다음 코드 예제에서는 RichTextBox 컨트롤 내에 현재 선택된 텍스트 또는 현재 삽입 지점 이후에 입력되는 텍스트의 색을 지정할 수 있는 ColorDialog를 표시합니다. 이 예제를 실행하려면 예제에 정의된 메서드가 richTextBox1이라는 RichTextBox 컨트롤이 포함된 Form 클래스에 추가되어 있어야 합니다.

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
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:
   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.set_Color(richTextBox1.get_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.get_Color() != richTextBox1.get_SelectionColor()) {
            // Change the selection color to the user specified color.
            richTextBox1.set_SelectionColor(colorDialog1.get_Color());
    }
} //ChangeMySelectionColor

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

RichTextBox 클래스
RichTextBox 멤버
System.Windows.Forms 네임스페이스
SelectionFont
Select