다음을 통해 공유


RichTextBox.SelectedText 속성

RichTextBox 내에서 선택된 텍스트를 가져오거나 설정합니다.

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

구문

‘선언
Public Overrides Property SelectedText As String
‘사용 방법
Dim instance As RichTextBox
Dim value As String

value = instance.SelectedText

instance.SelectedText = value
public override string SelectedText { get; set; }
public:
virtual property String^ SelectedText {
    String^ get () override;
    void set (String^ value) override;
}
/** @property */
public String get_SelectedText ()

/** @property */
public void set_SelectedText (String value)
public override function get SelectedText () : String

public override function set SelectedText (value : String)

속성 값

컨트롤에서 선택된 텍스트를 나타내는 문자열입니다.

예제

다음 코드 예제에서는 SelectionBullet 속성을 SelectionFont, SelectedTextSelectionColor 속성과 함께 사용하여 RichTextBox 컨트롤에 글머리 기호 목록을 만드는 방법을 보여 줍니다. 이 예제를 실행하려면 폼에 richTextBox1이라는 RichTextBox 컨트롤이 있어야 합니다.

Private Sub WriteTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   richTextBox1.Clear()
   ' Set the font for the opening text to a larger Arial font;
   richTextBox1.SelectionFont = New Font("Arial", 16)
   ' Assign the introduction text to the RichTextBox control.
   RichTextBox1.SelectedText = "The following is a list of bulleted items:" + ControlChars.Cr
   ' Set the Font for the first item to a smaller size Arial font.
   richTextBox1.SelectionFont = New Font("Arial", 12)
   ' Specify that the following items are to be added to a bulleted list.
   richTextBox1.SelectionBullet = True
   ' Set the color of the item text.
   richTextBox1.SelectionColor = Color.Red
   ' Assign the text to the bulleted item.
   richTextBox1.SelectedText = "Apples" + ControlChars.Cr
   ' Apply same font since font settings do not carry to next line.
   richTextBox1.SelectionFont = New Font("Arial", 12)
   richTextBox1.SelectionColor = Color.Orange
   richTextBox1.SelectedText = "Oranges" + ControlChars.Cr
   richTextBox1.SelectionFont = New Font("Arial", 12)
   richTextBox1.SelectionColor = Color.Purple
   richTextBox1.SelectedText = "Grapes" + ControlChars.Cr
   ' End the bulleted list.
   richTextBox1.SelectionBullet = False
   ' Specify the font size and string for text displayed below bulleted list.
   richTextBox1.SelectionFont = New Font("Arial", 16)
   richTextBox1.SelectedText = "Bulleted Text Complete!"
End Sub
private void WriteTextToRichTextBox()
{
   // Clear all text from the RichTextBox;
   richTextBox1.Clear();
   // Set the font for the opening text to a larger Arial font;
   richTextBox1.SelectionFont = new Font("Arial", 16);
   // Assign the introduction text to the RichTextBox control.
   richTextBox1.SelectedText = "The following is a list of bulleted items:" + "\n";
   // Set the Font for the first item to a smaller size Arial font.
   richTextBox1.SelectionFont = new Font("Arial", 12);
   // Specify that the following items are to be added to a bulleted list.
   richTextBox1.SelectionBullet = true;
   // Set the color of the item text.
   richTextBox1.SelectionColor = Color.Red;
   // Assign the text to the bulleted item.
   richTextBox1.SelectedText = "Apples" + "\n";
   // Apply same font since font settings do not carry to next line.
   richTextBox1.SelectionFont = new Font("Arial", 12);
   richTextBox1.SelectionColor = Color.Orange;
   richTextBox1.SelectedText = "Oranges" + "\n";
   richTextBox1.SelectionFont = new Font("Arial", 12);
   richTextBox1.SelectionColor = Color.Purple;
   richTextBox1.SelectedText = "Grapes" + "\n";
   // End the bulleted list.
   richTextBox1.SelectionBullet = false;
   // Specify the font size and string for text displayed below bulleted list.
   richTextBox1.SelectionFont = new Font("Arial", 16);
   richTextBox1.SelectedText = "Bulleted Text Complete!";
}
private:
   void WriteTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Set the font for the opening text to a larger Arial font;
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",16 );

      // Assign the introduction text to the RichTextBox control.
      richTextBox1->SelectedText = "The following is a list of bulleted items: \n";

      // Set the Font for the first item to a smaller size Arial font.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );

      // Specify that the following items are to be added to a bulleted list.
      richTextBox1->SelectionBullet = true;

      // Set the color of the item text.
      richTextBox1->SelectionColor = Color::Red;

      // Assign the text to the bulleted item.
      richTextBox1->SelectedText = "Apples \n";

      // Apply same font since font settings do not carry to next line.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );
      richTextBox1->SelectionColor = Color::Orange;
      richTextBox1->SelectedText = "Oranges \n";
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",12 );
      richTextBox1->SelectionColor = Color::Purple;
      richTextBox1->SelectedText = "Grapes \n";

      // End the bulleted list.
      richTextBox1->SelectionBullet = false;

      // Specify the font size and string for text displayed below bulleted list.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Arial",16 );
      richTextBox1->SelectedText = "Bulleted Text Complete!";
   }
private void WriteTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Set the font for the opening text to a larger Arial font;
    richTextBox1.set_SelectionFont(new Font("Arial", 16));
    // Assign the introduction text to the RichTextBox control.
    richTextBox1.set_SelectedText("The following is a list of bulleted items:"
        + "\n");
    // Set the Font for the first item to a smaller size Arial font.
    richTextBox1.set_SelectionFont(new Font("Arial", 12));
    // Specify that the following items are to be added to a bulleted list.
    richTextBox1.set_SelectionBullet(true);
    // Set the color of the item text.
    richTextBox1.set_SelectionColor(Color.get_Red());
    // Assign the text to the bulleted item.
    richTextBox1.set_SelectedText("Apples" + "\n");
    // Apply same font since font settings do not carry to next line.
    richTextBox1.set_SelectionFont(new Font("Arial", 12));
    richTextBox1.set_SelectionColor(Color.get_Orange());
    richTextBox1.set_SelectedText("Oranges" + "\n");
    richTextBox1.set_SelectionFont(new Font("Arial", 12));
    richTextBox1.set_SelectionColor(Color.get_Purple());
    richTextBox1.set_SelectedText("Grapes" + "\n");
    // End the bulleted list.
    richTextBox1.set_SelectionBullet(false);
    // Specify the font size and string for text displayed below bulleted list.
    richTextBox1.set_SelectionFont(new Font("Arial", 16));
    richTextBox1.set_SelectedText("Bulleted Text Complete!");
} //WriteTextToRichTextBox

플랫폼

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 네임스페이스