다음을 통해 공유


RichTextBox.SelectionAlignment 속성

현재 선택 영역 또는 삽입 지점에 적용할 맞춤 방식을 가져오거나 설정합니다.

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

구문

‘선언
Public Property SelectionAlignment As HorizontalAlignment
‘사용 방법
Dim instance As RichTextBox
Dim value As HorizontalAlignment

value = instance.SelectionAlignment

instance.SelectionAlignment = value
public HorizontalAlignment SelectionAlignment { get; set; }
public:
property HorizontalAlignment SelectionAlignment {
    HorizontalAlignment get ();
    void set (HorizontalAlignment value);
}
/** @property */
public HorizontalAlignment get_SelectionAlignment ()

/** @property */
public void set_SelectionAlignment (HorizontalAlignment value)
public function get SelectionAlignment () : HorizontalAlignment

public function set SelectionAlignment (value : HorizontalAlignment)

속성 값

HorizontalAlignment 값 중 하나입니다.

예외

예외 형식 조건

InvalidEnumArgumentException

지정된 값이 HorizontalAlignment 클래스에 정의된 값 중 하나가 아닌 경우

설명

컨트롤에 선택된 단락이 없는 경우 이 속성을 설정하면 삽입 지점이 있는 단락과, 맞춤 속성 설정이 있는 단락 다음에 만들어진 단락에 해당 맞춤 설정이 적용됩니다. 예를 들어, RichTextBox 컨트롤에 두 개의 단락이 있고 두 번째 단락 내에 삽입 지점이 있는 경우, SelectionAlignment 속성을 HorizontalAlignment.Center로 설정하면 삽입 지점의 단락이 컨트롤의 가운데에 표시됩니다. 또한, 두 번째 단락 다음에 세 번째 단락을 만든 경우에도 세 번째 단락이 컨트롤의 가운데에 맞춰집니다.

컨트롤 내에서 특정 범위를 선택하고 이 속성을 설정하면 선택된 모든 단락은 이 속성 설정에 따라 맞춰집니다. 이 속성을 사용하면 RichTextBox에 만든 문서의 단락을 맞출 수 있습니다. 예를 들어, 문서의 모든 단락을 가운데로 맞추려면 컨트롤의 단락을 모두 선택하고 SelectionAlignment 속성을 HorizontalAlignment.Center로 설정하면 됩니다.

참고

SelectionAlignment에서는 텍스트 선택 영역에 혼합 맞춤을 사용한 여러 단락이 포함되어 있는 경우 SelectionAlignment.Left를 반환합니다.

예제

다음 코드 예제에서는 RichTextBox 내에서 텍스트를 정렬하는 방법을 보여 줍니다. 이 예제를 실행하려면 이름이 richTextBox1RichTextBox 컨트롤이 폼에 추가되어 있어야 합니다.

Private Sub WriteCenteredTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   richTextBox1.Clear()
   ' Set the foreground color of the text.
   richTextBox1.SelectionColor = Color.Red
   ' Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center
   ' Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12)
   ' Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property."

End Sub
private void WriteCenteredTextToRichTextBox()
{
   // Clear all text from the RichTextBox;
   richTextBox1.Clear();
   // Set the foreground color of the text.
   richTextBox1.ForeColor = Color.Red;
   // Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
   // Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12);
   // Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property.\n";
}
private:
   void WriteCenteredTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Set the foreground color of the text.
      richTextBox1->ForeColor = Color::Red;

      // Set the alignment of the text that follows.
      richTextBox1->SelectionAlignment = HorizontalAlignment::Center;

      // Set the font for the text.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Lucinda Console",12 );

      // Set the text within the control.
      richTextBox1->SelectedText = "This text is centered using the SelectionAlignment property.\n";
   }
private void WriteCenteredTextToRichTextBox()
{
    // Clear all text from the RichTextBox;
    richTextBox1.Clear();
    // Set the foreground color of the text.
    richTextBox1.set_ForeColor(Color.get_Red());
    // Set the alignment of the text that follows.
    richTextBox1.set_SelectionAlignment(HorizontalAlignment.Center);
    // Set the font for the text.
    richTextBox1.set_SelectionFont(new Font("Lucinda Console", 12));
    // Set the text within the control.
    richTextBox1.set_SelectedText("This text is centered using the"
        + "SelectionAlignment property.\n");
} //WriteCenteredTextToRichTextBox

플랫폼

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 네임스페이스
HorizontalAlignment 열거형