CheckBox.CheckState 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 status CheckBox.
public:
property System::Windows::Forms::CheckState CheckState { System::Windows::Forms::CheckState get(); void set(System::Windows::Forms::CheckState value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.Forms.CheckState CheckState { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.CheckState : System.Windows.Forms.CheckState with get, set
Public Property CheckState As CheckState
Nilai Properti
Salah CheckState satu nilai enumerasi. Nilai defaultnya adalah Unchecked
.
- Atribut
Pengecualian
Nilai yang ditetapkan bukan salah CheckState satu nilai enumerasi.
Contoh
Contoh kode berikut menampilkan nilai tiga properti dalam label. Properti ThreeState bergantian antara true
dan false
dengan klik alternatif kontrol dan CheckAlign alternatif antara MiddleRight
nilai System.Drawing.ContentAlignmentdan MiddleLeft
. Contoh ini memperlihatkan bagaimana nilai properti berubah saat ThreeState properti berubah dan kontrol dicentang. Contoh ini mengharuskan , CheckBoxLabel dan Button semuanya telah diinstansiasi pada formulir dan bahwa label cukup besar untuk menampilkan tiga baris teks, serta referensi ke System.Drawing namespace. Kode ini harus dipanggil dalam Click penanganan aktivitas kontrol.
private:
void AdjustMyCheckBoxProperties()
{
// Concatenate the property values together on three lines.
label1->Text = String::Format( "ThreeState: {0}\nChecked: {1}\nCheckState: {2}",
checkBox1->ThreeState, checkBox1->Checked, checkBox1->CheckState );
// Change the ThreeState and CheckAlign properties on every other click.
if ( !checkBox1->ThreeState )
{
checkBox1->ThreeState = true;
checkBox1->CheckAlign = ContentAlignment::MiddleRight;
}
else
{
checkBox1->ThreeState = false;
checkBox1->CheckAlign = ContentAlignment::MiddleLeft;
}
}
private void AdjustMyCheckBoxProperties()
{
// Change the ThreeState and CheckAlign properties on every other click.
if (!checkBox1.ThreeState)
{
checkBox1.ThreeState = true;
checkBox1.CheckAlign = ContentAlignment.MiddleRight;
}
else
{
checkBox1.ThreeState = false;
checkBox1.CheckAlign = ContentAlignment.MiddleLeft;
}
// Concatenate the property values together on three lines.
label1.Text = "ThreeState: " + checkBox1.ThreeState.ToString() + "\n" +
"Checked: " + checkBox1.Checked.ToString() + "\n" +
"CheckState: " + checkBox1.CheckState.ToString();
}
Private Sub AdjustMyCheckBoxProperties()
' Change the ThreeState and CheckAlign properties on every other click.
If Not checkBox1.ThreeState Then
checkBox1.ThreeState = True
checkBox1.CheckAlign = ContentAlignment.MiddleRight
Else
checkBox1.ThreeState = False
checkBox1.CheckAlign = ContentAlignment.MiddleLeft
End If
' Concatenate the property values together on three lines.
label1.Text = "ThreeState: " & checkBox1.ThreeState.ToString() & ControlChars.Cr & _
"Checked: " & checkBox1.Checked.ToString() & ControlChars.Cr & _
"CheckState: " & checkBox1.CheckState.ToString()
End Sub
Keterangan
ThreeState Jika properti diatur ke false
, CheckState nilai properti hanya dapat diatur ke CheckState.Indeterminate
dalam kode dan bukan oleh interaksi pengguna.
Tabel berikut ini menjelaskan System.Windows.Forms.Appearance kontrol CheckBox dalam statusnya yang berbeda untuk Normal
kontrol CheckBox.Appearancegaya dan Button
.
CheckState | Penampilan.Normal | Appearance.Button |
---|---|---|
Checked |
menampilkan CheckBox tanda centang. | Kontrol tampak tenggelam. |
Unchecked |
Kosong CheckBox . | Kontrol muncul dinaikkan. |
Indeterminate |
CheckBox menampilkan tanda centang dan berbayang. | Kontrol tampak datar. |