Поделиться через


RichTextBox.SelectionCharOffset Свойство

Определение

Возвращает или задает, отображается ли текст в элементе управления на базовом уровне, в качестве надстрочного или подстрочного подстрока ниже базового плана.

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

Значение свойства

Число, указывающее смещение символов.

Атрибуты

Исключения

Указанное значение меньше -2000 или больше 2000.

Примеры

В следующем примере кода показано, как указать надстрочный и подстрочный текст в свойстве RichTextBoxSelectionCharOffset . В этом примере требуется, чтобы RichTextBox элемент управления с именем richTextBox1был добавлен в форму.

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.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 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

Комментарии

Значение этого свойства должно находиться в диапазоне от -2000 до 2000.

Если это свойство равно нулю, текст появляется на базовом уровне. Если это положительное число, то число указывает количество пикселей, с помощью которого нужно увеличить выделение текста над базовым показателем. Если это отрицательное число, это число указывает количество пикселей, по которым следует подстроить выделение текста. Это свойство можно использовать для указания текста в качестве надстрочного или подстрочного.

Если текст не выбран, смещение применяется к текущей точке вставки и ко всему тексту, который пользователь вводит после точки вставки. Смещение символов применяется, пока свойство не изменится на другое значение или пока точка вставки не будет перемещена в другой раздел в элементе управления.

Если текст выбран в элементе управления, выделенный текст и любой текст, введенный после выделения текста, будет иметь значение этого свойства, примененного к нему. Это свойство можно использовать для создания надстрочного и подстрочного текста для таких приложений, как математические выражения.

Применяется к