RichTextBox.SelectionCharOffset RichTextBox.SelectionCharOffset RichTextBox.SelectionCharOffset RichTextBox.SelectionCharOffset Property

定义

获取或设置控件中的文本是显示在基线上、作为上标还是作为基线下方的下标。Gets or sets whether text in the control appears on the baseline, as a superscript, or as a subscript below the baseline.

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

属性值

指定字符偏移量的数字。A number that specifies the character offset.

异常

指定的值小于 -2000 或大于 2000。The specified value was less than -2000 or greater than 2000.

示例

下面的代码示例演示如何RichTextBox SelectionCharOffset使用属性在中指定上标和下标文本。The following code example demonstrates how to specify superscript and subscript text within the RichTextBox using the SelectionCharOffset property. 此示例要求RichTextBox已将名为richTextBox1的控件添加到窗体中。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

注解

此属性的值必须介于-2000 和2000之间。The value of this property must be between -2000 and 2000.

如果将此属性设置为零,则文本将显示在基线上。If this property is set to zero, the text appears on the baseline. 如果是正数,则该数字指定在基线上方引发文本选择所依据的像素数。If it is a positive number, the number specifies the number of pixels by which to raise the text selection above the baseline. 如果为负数,此数字指定选定文本所选的像素数。If it is a negative number, this number specifies the number of pixels by which to subscript the text selection. 您可以使用此属性将文本指定为上标或下标。You can use this property to specify text as superscript or subscript.

如果未选择任何文本,则偏移量将应用于当前插入点和用户在插入点之后键入的所有文本。If no text is selected, the offset is applied to the current insertion point and to all text that the user types after the insertion point. 在将属性更改为其他值或将插入点移动到控件内的其他部分之前,将一直使用字符偏移量。The character offset applies until the property is changed to a different value or until the insertion point is moved to a different section within the control.

如果在控件中选择文本,则选定文本和在选择文本后输入的任何文本都将应用此属性的值。If text is selected within the control, the selected text and any text entered after the text selection will have the value of this property applied to it. 您可以使用此属性为此类应用程序创建与数学表达式相同的上标和下标文本。You can use this property to create superscript and subscript text for such applications as mathematical expressions.

适用于