RichTextBox.SelectionCharOffset Vlastnost

Definice

Získá nebo nastaví, zda se text v ovládacím prvku zobrazí na účaří, jako horní index nebo jako dolní index pod směrný plán.

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

Hodnota vlastnosti

Int32

Číslo, které určuje posun znaku.

Atributy

Výjimky

Zadaná hodnota byla menší než -2000 nebo větší než 2000.

Příklady

Následující příklad kódu ukazuje, jak zadat horní index a dolní index text v rámci RichTextBox použití SelectionCharOffset vlastnosti. Tento příklad vyžaduje přidání RichTextBox ovládacího prvku pojmenovaného richTextBox1do formuláře.

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

Poznámky

Hodnota této vlastnosti musí být v rozsahu -2000 až 2000.

Pokud je tato vlastnost nastavená na nulu, zobrazí se text na účaří. Pokud se jedná o kladné číslo, určuje číslo počet pixelů, o které se má zvýšit výběr textu nad směrný plán. Pokud se jedná o záporné číslo, určuje toto číslo počet pixelů, o které se má vybrat text v indexu. Tuto vlastnost můžete použít k zadání textu jako horního nebo dolního indexu.

Pokud není vybraný žádný text, posun se použije na aktuální kurzor a na veškerý text, který uživatel za kurzorem zadá. Posun znaku se použije, dokud se vlastnost nezmění na jinou hodnotu nebo dokud se kurzor přesune do jiného oddílu v ovládacím prvku.

Pokud je text vybrán v ovládacím prvku, vybraný text a veškerý text zadaný po výběru textu bude mít hodnotu této vlastnosti použitou na něj. Tuto vlastnost můžete použít k vytvoření textu horního a dolního indexu pro takové aplikace, jako jsou matematické výrazy.

Platí pro