Control.Text 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 teks yang terkait dengan kontrol ini.
public:
virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public virtual string Text { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Text : string with get, set
Public Overridable Property Text As String
Nilai Properti
Teks yang terkait dengan kontrol ini.
- Atribut
Contoh
Contoh kode berikut membuat GroupBox dan mengatur beberapa properti umumnya. Contoh membuat TextBox dan mengaturnya Location dalam kotak grup. Selanjutnya, ini mengatur Text properti kotak grup, dan menambungkan kotak grup ke bagian atas formulir. Terakhir, ini menonaktifkan kotak grup dengan mengatur Enabled properti ke false, yang menyebabkan semua kontrol yang terkandung dalam kotak grup dinonaktifkan.
// Add a GroupBox to a form and set some of its common properties.
private:
void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox^ groupBox1 = gcnew GroupBox;
TextBox^ textBox1 = gcnew TextBox;
textBox1->Location = Point(15,15);
groupBox1->Controls->Add( textBox1 );
// Set the Text and Dock properties of the GroupBox.
groupBox1->Text = "MyGroupBox";
groupBox1->Dock = DockStyle::Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1->Enabled = false;
// Add the Groupbox to the form.
this->Controls->Add( groupBox1 );
}
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox groupBox1 = new GroupBox();
TextBox textBox1 = new TextBox();
textBox1.Location = new Point(15, 15);
groupBox1.Controls.Add(textBox1);
// Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox";
groupBox1.Dock = DockStyle.Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = false;
// Add the Groupbox to the form.
this.Controls.Add(groupBox1);
}
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
' Create a GroupBox and add a TextBox to it.
Dim groupBox1 As New GroupBox()
Dim textBox1 As New TextBox()
textBox1.Location = New Point(15, 15)
groupBox1.Controls.Add(textBox1)
' Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox"
groupBox1.Dock = DockStyle.Top
' Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = False
' Add the Groupbox to the form.
Me.Controls.Add(groupBox1)
End Sub
Keterangan
Properti Text kontrol digunakan secara berbeda oleh setiap kelas turunan. Misalnya Text properti dari ditampilkan Form di bilah judul di bagian atas formulir, cukup kecil dalam jumlah karakter, dan biasanya menampilkan aplikasi atau nama dokumen. Namun, Text properti RichTextBox bisa besar dan dapat mencakup banyak karakter nonvisual yang digunakan untuk memformat teks. Misalnya, teks yang RichTextBox ditampilkan dalam dapat diformat dengan menyesuaikan properti, atau dengan penambahan Font spasi atau karakter tab untuk meratakan teks.
Catatan Bagi Inheritor
Saat mengambil alih Text properti di kelas turunan, gunakan properti kelas Text dasar untuk memperluas implementasi dasar. Jika tidak, Anda harus menyediakan semua implementasi. Anda tidak diharuskan untuk mengambil alih properti get dan set aksesor Text ; Anda hanya dapat mengambil alih satu jika diperlukan.