RichTextBox.SelectionCharOffset 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
可設定控制項中的文字是否出現在基線、上標或基線下方的下標。
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
屬性值
一個指定字元偏移量的數字。
- 屬性
例外狀況
指定值小於 -2000 或大於2000。
範例
以下程式碼範例示範如何使用屬性在 內RichTextBoxSelectionCharOffset指定上標與下標文字。 此範例要求 RichTextBox 表單中加入一個名為 richTextBox1的控制項。
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之間。
若此屬性設為零,文字會出現在基線。 若為正數,則該數字指定將文字選取提升至基線以上的像素數。 若為負數,則此數字指定用來下標文字選擇的像素數。 你可以利用這個特性來指定文字為上標或下標。
若未選取任何文字,則偏移量會套用到當前插入點以及使用者在插入點之後輸入的所有文字。 字元偏移量會持續,直到屬性被更改為其他值,或插入點移至控制項內的其他區塊。
若在控制項內選取文字,所選文字及後輸入的任何文字都會套用此屬性的值。 你可以利用此特性為數學表達式等應用建立上標與下標文字。