RichTextBox.SelectionCharOffset Propriété

Définition

Obtient ou définit une valeur qui indique si le texte du contrôle s'affiche sur la ligne de base, au-dessus de la ligne de base (exposant) ou au-dessous de la ligne de base (indice).

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

Valeur de propriété

Int32

Nombre qui signifie l'offset des caractères.

Attributs

Exceptions

La valeur spécifiée est inférieure à -2000 ou supérieure à 2000.

Exemples

L’exemple de code suivant montre comment spécifier le texte en exposant et en exposant dans la propriété à l’aide RichTextBox de la SelectionCharOffset propriété. Cet exemple nécessite qu’un RichTextBox contrôle nommé richTextBox1ait été ajouté au formulaire.

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

Remarques

La valeur de cette propriété doit être comprise entre -2000 et 2000.

Si cette propriété est définie sur zéro, le texte apparaît sur la base de référence. S’il s’agit d’un nombre positif, le nombre spécifie le nombre de pixels par lequel élever la sélection de texte au-dessus de la ligne de base. S’il s’agit d’un nombre négatif, ce nombre spécifie le nombre de pixels par lequel subscripteur la sélection de texte. Vous pouvez utiliser cette propriété pour spécifier du texte comme exposant ou indice.

Si aucun texte n’est sélectionné, le décalage est appliqué au point d’insertion actuel et à tout le texte que l’utilisateur type après le point d’insertion. Le décalage de caractères s’applique jusqu’à ce que la propriété soit modifiée en une valeur différente ou jusqu’à ce que le point d’insertion soit déplacé vers une autre section au sein du contrôle.

Si le texte est sélectionné dans le contrôle, le texte sélectionné et tout texte entré après la sélection de texte aura la valeur de cette propriété. Vous pouvez utiliser cette propriété pour créer du texte exposant et exposant pour des applications telles que des expressions mathématiques.

S’applique à