Bagikan melalui


RichTextBox.SelectionAlignment Properti

Definisi

Mendapatkan atau mengatur perataan untuk diterapkan ke pilihan atau titik penyisipan saat ini.

public:
 property System::Windows::Forms::HorizontalAlignment SelectionAlignment { System::Windows::Forms::HorizontalAlignment get(); void set(System::Windows::Forms::HorizontalAlignment value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.HorizontalAlignment SelectionAlignment { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionAlignment : System.Windows.Forms.HorizontalAlignment with get, set
Public Property SelectionAlignment As HorizontalAlignment

Nilai Properti

Salah HorizontalAlignment satu nilai.

Atribut

Pengecualian

Nilai yang ditentukan bukan salah satu nilai yang ditentukan di HorizontalAlignment kelas .

Contoh

Contoh kode berikut menunjukkan cara meratakan teks dalam RichTextBox. Contoh ini mengharuskan RichTextBox kontrol, bernama richTextBox1, telah ditambahkan ke formulir.

private:
   void WriteCenteredTextToRichTextBox()
   {
      // Clear all text from the RichTextBox;
      richTextBox1->Clear();

      // Set the foreground color of the text.
      richTextBox1->ForeColor = Color::Red;

      // Set the alignment of the text that follows.
      richTextBox1->SelectionAlignment = HorizontalAlignment::Center;

      // Set the font for the text.
      richTextBox1->SelectionFont = gcnew System::Drawing::Font( "Lucinda Console",12 );

      // Set the text within the control.
      richTextBox1->SelectedText = "This text is centered using the SelectionAlignment property.\n";
   }
private void WriteCenteredTextToRichTextBox()
{
   // Clear all text from the RichTextBox;
   richTextBox1.Clear();
   // Set the foreground color of the text.
   richTextBox1.ForeColor = Color.Red;
   // Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
   // Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12);
   // Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property.\n";
}
Private Sub WriteCenteredTextToRichTextBox()
   ' Clear all text from the RichTextBox;
   richTextBox1.Clear()
   ' Set the foreground color of the text.
   richTextBox1.SelectionColor = Color.Red
   ' Set the alignment of the text that follows.
   richTextBox1.SelectionAlignment = HorizontalAlignment.Center
   ' Set the font for the text.
   richTextBox1.SelectionFont = new Font("Lucinda Console", 12)
   ' Set the text within the control.
   richTextBox1.SelectedText = "This text is centered using the SelectionAlignment property."

End Sub

Keterangan

Jika tidak ada paragraf yang dipilih dalam kontrol, mengatur properti ini menerapkan pengaturan perataan ke paragraf tempat titik penyisipan muncul serta paragraf yang dibuat setelah paragraf yang memiliki pengaturan properti perataan. Misalnya, jika ada dua paragraf dalam RichTextBox kontrol dan titik penyisipan terletak di dalam paragraf kedua. Jika Anda mengatur SelectionAlignment properti ke HorizontalAlignment.Center, paragraf di titik penyisipan akan berpusat di dalam kontrol. Jika paragraf ketiga dibuat setelah paragraf kedua, paragraf tersebut juga diratakan ke tengah kontrol.

Jika pilihan dibuat dalam kontrol saat properti diatur, semua paragraf yang dipilih diratakan berdasarkan pengaturan properti ini. Anda dapat menggunakan properti ini untuk meratakan paragraf dalam dokumen yang sedang dibuat di RichTextBox. Misalnya, jika Anda ingin semua paragraf dalam dokumen dipusatkan, Anda dapat memilih semua paragraf dalam kontrol dan mengatur properti ke SelectionAlignmentHorizontalAlignment.Center.

Nota

SelectionAlignment SelectionAlignment.Left mengembalikan saat pilihan teks berisi beberapa paragraf dengan perataan campuran.

Berlaku untuk

Lihat juga