RichTextBox.SelectionCharOffset Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
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
Čí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í a dolní index text v rámci RichTextBox použití SelectionCharOffset vlastnosti. Tento příklad vyžaduje, aby RichTextBox byl do formuláře přidán ovládací prvek s názvem 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
Poznámky
Hodnota této vlastnosti musí být mezi -2000 a 2000.
Pokud je tato vlastnost nastavena na nulu, text se zobrazí 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ů, podle kterých 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 platí, dokud se vlastnost nezmění na jinou hodnotu nebo dokud se kurzor nepřesune do jiného oddílu v ovládacím prvku.
Pokud je text vybrán v ovládacím prvku, bude mít vybraný text a jakýkoli text zadaný po výběru textu hodnotu této vlastnosti. Tuto vlastnost můžete použít k vytvoření textu horního a dolního indexu pro takové aplikace, jako jsou matematické výrazy.