RichTextBox.SelectionCharOffset Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur apakah teks dalam kontrol muncul di garis besar, sebagai superskrip, atau sebagai subskrip di bawah garis besar.
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
Nilai Properti
Angka yang menentukan offset karakter.
- Atribut
Pengecualian
Nilai yang ditentukan kurang dari -2000 atau lebih besar dari 2000.
Contoh
Contoh kode berikut menunjukkan cara menentukan teks superskrip dan subskrip dalam RichTextBox menggunakan SelectionCharOffset properti . Contoh ini mengharuskan RichTextBox kontrol, bernama richTextBox1, telah ditambahkan ke formulir.
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
Keterangan
Nilai properti ini harus antara -2000 dan 2000.
Jika properti ini diatur ke nol, teks akan muncul pada garis besar. Jika berupa angka positif, angka menentukan jumlah piksel untuk menaikkan pilihan teks di atas garis besar. Jika berupa angka negatif, angka ini menentukan jumlah piksel untuk mensubskripsikan pilihan teks. Anda dapat menggunakan properti ini untuk menentukan teks sebagai superskrip atau subskrip.
Jika tidak ada teks yang dipilih, offset diterapkan ke titik penyisipan saat ini dan ke semua teks yang jenis pengguna setelah titik penyisipan. Offset karakter berlaku hingga properti diubah ke nilai yang berbeda atau sampai titik penyisipan dipindahkan ke bagian lain dalam kontrol.
Jika teks dipilih dalam kontrol, teks yang dipilih dan teks apa pun yang dimasukkan setelah pemilihan teks akan memiliki nilai properti ini yang diterapkan padanya. Anda dapat menggunakan properti ini untuk membuat teks superskrip dan subskrip untuk aplikasi seperti ekspresi matematika.