RichTextBox.SelectionCharOffset Właściwość

Definicja

Pobiera lub ustawia, czy tekst w kontrolce jest wyświetlany w punkcie odniesienia, jako indeks górny, czy jako indeks dolny poniżej punktu odniesienia.

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

Wartość właściwości

Int32

Liczba określająca przesunięcie znaku.

Atrybuty

Wyjątki

Określona wartość była mniejsza niż -2000 lub większa niż 2000.

Przykłady

W poniższym przykładzie kodu pokazano, jak określić tekst indeksu górnego i dolnego w obrębie RichTextBox właściwości .SelectionCharOffset Ten przykład wymaga dodania RichTextBox kontrolki o nazwie richTextBox1do formularza.

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

Uwagi

Wartość tej właściwości musi należeć do zakresu od -2000 do 2000.

Jeśli ta właściwość jest ustawiona na zero, tekst pojawi się w punkcie odniesienia. Jeśli jest to liczba dodatnia, liczba określa liczbę pikseli, za pomocą których należy podnieść zaznaczenie tekstu nad punktem odniesienia. Jeśli jest to liczba ujemna, ta liczba określa liczbę pikseli, o jaką ma być indeks dolny zaznaczenia tekstu. Tej właściwości można użyć do określenia tekstu jako indeksu górnego lub indeksu dolnego.

Jeśli tekst nie jest zaznaczony, przesunięcie jest stosowane do bieżącego punktu wstawiania i do całego tekstu, który użytkownik wpisze po punkcie wstawiania. Przesunięcie znaku ma zastosowanie do momentu zmiany właściwości na inną wartość lub do momentu przeniesienia punktu wstawiania do innej sekcji w kontrolce.

Jeśli tekst jest zaznaczony w kontrolce, zaznaczony tekst i dowolny tekst wprowadzony po zaznaczeniu tekstu będą miały do niego zastosowaną wartość tej właściwości. Za pomocą tej właściwości można utworzyć tekst indeksu górnego i indeksu dolnego dla takich aplikacji, jak wyrażenia matematyczne.

Dotyczy