Freigeben über


RichTextBox.SelectionCharOffset Eigenschaft

Definition

Ruft ab oder legt fest, ob Text im Steuerelement auf der Basislinie, als hochgestellt oder als Tiefgestellt unterhalb der Basislinie angezeigt wird.

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

Eigenschaftswert

Eine Zahl, die den Zeichenoffset angibt.

Attribute

Ausnahmen

Der angegebene Wert war kleiner als -2000 oder größer als 2000.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie hochgestellter und tiefgestellter Text in der RichTextBox Verwendung der SelectionCharOffset Eigenschaft angegeben wird. Dieses Beispiel erfordert, dass dem Formular ein Steuerelement mit dem Namen hinzugefügt wurde.This example requires that a RichTextBox control, named richTextBox1, has been added to the form.

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

Hinweise

Der Wert dieser Eigenschaft muss zwischen -2000 und 2000 sein.

Wenn diese Eigenschaft auf Null festgelegt ist, wird der Text auf der Basislinie angezeigt. Wenn es sich um eine positive Zahl handelt, gibt die Zahl die Anzahl der Pixel an, um die die Textauswahl oberhalb der Basislinie ausgelöst werden soll. Wenn es sich um eine negative Zahl handelt, gibt diese Zahl die Anzahl der Pixel an, um die die Textauswahl tiefgestellt werden soll. Mit dieser Eigenschaft können Sie Text als hochgestellt oder tiefgestellt angeben.

Wenn kein Text markiert ist, wird der Offset auf die aktuelle Einfügemarke und auf den gesamten Text angewendet, den der Benutzer nach der Einfügemarke eingibt. Der Zeichenoffset wird angewendet, bis die Eigenschaft in einen anderen Wert geändert wird oder bis die Einfügemarke in einen anderen Abschnitt innerhalb des Steuerelements verschoben wird.

Wenn Text innerhalb des Steuerelements markiert ist, wird der markierte Text und jeder Text, der nach der Textauswahl eingegeben wurde, den Wert dieser Eigenschaft zugewiesen. Mit dieser Eigenschaft können Sie hochgestellten und tiefgestellten Text für Anwendungen wie mathematische Ausdrücke erstellen.

Gilt für: