다음을 통해 공유


RichTextBox.SelectionCharOffset 속성

컨트롤의 텍스트가 기준선 위에 위 첨자로 표시되거나 기준선 아래에 아래 첨자로 표시되는지 여부를 가져오거나 설정합니다.

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

구문

‘선언
Public Property SelectionCharOffset As Integer
‘사용 방법
Dim instance As RichTextBox
Dim value As Integer

value = instance.SelectionCharOffset

instance.SelectionCharOffset = value
public int SelectionCharOffset { get; set; }
public:
property int SelectionCharOffset {
    int get ();
    void set (int value);
}
/** @property */
public int get_SelectionCharOffset ()

/** @property */
public void set_SelectionCharOffset (int value)
public function get SelectionCharOffset () : int

public function set SelectionCharOffset (value : int)

속성 값

문자 오프셋을 지정하는 숫자입니다.

예외

예외 형식 조건

ArgumentException

지정된 값이 -2000보다 작거나 2000보다 큰 경우

설명

이 속성은 -2000에서 2000 사이의 값으로 설정해야 합니다.

이 속성이 0으로 설정되어 있으면 텍스트가 기준선에 표시됩니다. 이 속성 값이 양수이면 해당 숫자는 텍스트 선택 영역을 기준선 위로 올릴 픽셀의 수를 나타냅니다. 이 속성 값이 음수이면 해당 숫자는 텍스트 선택 영역을 기준선 아래로 내릴 픽셀의 수를 나타냅니다. 이 속성을 사용하여 텍스트를 위 첨자 또는 아래 첨자로 지정할 수 있습니다.

선택된 텍스트가 없으면 현재 삽입 지점과 삽입 지점 다음에 사용자가 입력한 모든 텍스트에 오프셋이 적용됩니다. 해당 속성이 다른 값으로 변경되거나 삽입 지점이 컨트롤 내의 다른 부분으로 이동할 때까지 문자 오프셋이 적용됩니다.

컨트롤 내에서 텍스트를 선택하는 경우 선택한 텍스트 및 텍스트를 선택한 다음 입력한 모든 텍스트는 선택한 텍스트에 적용된 이 속성의 값을 사용합니다. 이 속성을 사용하면 수식을 처리하는 응용 프로그램 등에서 위 첨자 및 아래 첨자 텍스트를 만들 수 있습니다.

예제

다음 코드 예제에서는 SelectionCharOffset 속성을 사용하여 RichTextBox 내에 위 첨자 및 아래 첨자 텍스트를 지정하는 방법을 보여 줍니다. 이 예제를 실행하려면 이름이 richTextBox1RichTextBox 컨트롤이 폼에 추가되어 있어야 합니다.

Private Sub WriteOffsetTextToRichTextBox()
   ' Clear all text from the RichTextBox.
   RichTextBox1.Clear()
   ' Set the font for the text.
   RichTextBox1.SelectionFont = New Font("Lucinda Console", 12)
   ' Set the foreground color of the text.
   RichTextBox1.SelectionColor = Color.Purple
   ' Set the baseline text.
   RichTextBox1.SelectedText = "10"
   ' Set the CharOffset to display superscript text.
   RichTextBox1.SelectionCharOffset = 10
   ' Set the superscripted text.    
   RichTextBox1.SelectedText = "2"
   ' Reset the CharOffset to display text at the baseline.
   RichTextBox1.SelectionCharOffset = 0
   RichTextBox1.SelectedText = ControlChars.CrLf + ControlChars.CrLf
   ' Change the forecolor of the next text selection.
   RichTextBox1.SelectionColor = Color.Blue
   ' Set the baseline text.
   RichTextBox1.SelectedText = "777"
   ' Set the CharOffset to display subscript text.
   RichTextBox1.SelectionCharOffset = -10
   ' Set the subscripted text.  
   RichTextBox1.SelectedText = "3"
   ' Reset the CharOffset to display text at the baseline.
   RichTextBox1.SelectionCharOffset = 0
End Sub
private void WriteOffsetTextToRichTextBox()
{
    // Clear all text from the RichTextBox.
    richTextBox1.Clear();
    // Set the font for the text.
    richTextBox1.SelectionFont = new Font("Lucinda Console", 12);
    // Set the foreground color of the text.
    richTextBox1.SelectionColor = Color.Purple;
    // Set the baseline text.
    richTextBox1.SelectedText = "10";
    // Set the CharOffset to display superscript text.
    richTextBox1.SelectionCharOffset = 10;
    // Set the superscripted text.    
    richTextBox1.SelectedText = "2";
    // Reset the CharOffset to display text at the baseline.
    richTextBox1.SelectionCharOffset = 0;
    richTextBox1.AppendText("\n\n");
    // Change the forecolor of the next text selection.
    richTextBox1.SelectionColor = Color.Blue;
    // Set the baseline text.
    richTextBox1.SelectedText = "77";
    // Set the CharOffset to display subscript text.
    richTextBox1.SelectionCharOffset = -10;
    // Set the subscripted text.  
    richTextBox1.SelectedText = "3";
    // Reset the CharOffset to display text at the baseline.
    richTextBox1.SelectionCharOffset = 0; 
}
private:
   void WriteOffsetTextToRichTextBox()
   {
      // Clear all text from the RichTextBox.
      richTextBox1->Clear();

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

      // Set the foreground color of the text.
      richTextBox1->SelectionColor = Color::Purple;

      // Set the baseline text.
      richTextBox1->SelectedText = "10";

      // Set the CharOffset to display superscript text.
      richTextBox1->SelectionCharOffset = 10;

      // Set the superscripted text. 
      richTextBox1->SelectedText = "2";

      // Reset the CharOffset to display text at the baseline.
      richTextBox1->SelectionCharOffset = 0;
      richTextBox1->AppendText( "\n\n" );

      // Change the forecolor of the next text selection.
      richTextBox1->SelectionColor = Color::Blue;

      // Set the baseline text.
      richTextBox1->SelectedText = "77";

      // Set the CharOffset to display subscript text.
      richTextBox1->SelectionCharOffset = -10;

      // Set the subscripted text.  
      richTextBox1->SelectedText = "3";

      // Reset the CharOffset to display text at the baseline.
      richTextBox1->SelectionCharOffset = 0;
   }
private void WriteOffsetTextToRichTextBox()
{
    // Clear all text from the RichTextBox.
    richTextBox1.Clear();
    // Set the font for the text.
    richTextBox1.set_SelectionFont(new Font("Lucinda Console", 12));
    // Set the foreground color of the text.
    richTextBox1.set_SelectionColor(Color.get_Purple());
    // Set the baseline text.
    richTextBox1.set_SelectedText("10");
    // Set the CharOffset to display superscript text.
    richTextBox1.set_SelectionCharOffset(10);
    // Set the superscripted text.    
    richTextBox1.set_SelectedText("2");
    // Reset the CharOffset to display text at the baseline.
    richTextBox1.set_SelectionCharOffset(0);
    richTextBox1.AppendText("\n\n");
    // Change the forecolor of the next text selection.
    richTextBox1.set_SelectionColor(Color.get_Blue());
    // Set the baseline text.
    richTextBox1.set_SelectedText("77");
    // Set the CharOffset to display subscript text.
    richTextBox1.set_SelectionCharOffset(-10);
    // Set the subscripted text.  
    richTextBox1.set_SelectedText("3");
    // Reset the CharOffset to display text at the baseline.
    richTextBox1.set_SelectionCharOffset(0);
} //WriteOffsetTextToRichTextBox

플랫폼

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