Share via


CheckBox.Checked Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah CheckBox berada dalam status dicentang.

public:
 property bool Checked { bool get(); void set(bool value); };
[System.ComponentModel.Bindable(true)]
public bool Checked { get; set; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.SettingsBindable(true)]
public bool Checked { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Checked : bool with get, set
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.SettingsBindable(true)>]
member this.Checked : bool with get, set
Public Property Checked As Boolean

Nilai Properti

trueCheckBox jika dalam status diperiksa; jika tidak, false. Nilai defaultnya adalah false.

Catatan: Jika ThreeState properti diatur ke true, Checked properti akan kembali true untuk Checked atau IndeterminateCheckState.

Atribut

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 ContentAlignment nilai MiddleRight dan MiddleLeft. Contoh ini memperlihatkan bagaimana nilai properti berubah saat ThreeState properti berubah dan kontrol dicentang. Contoh ini mengharuskan bahwa CheckBox, Label dan Button semuanya telah dibuat 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

Saat nilai adalah true, CheckBox bagian kontrol menampilkan tanda centang. Appearance Jika properti diatur ke Button, kontrol akan muncul tenggelam ketika Checked sedang dan true dinaikkan seperti tombol standar saat false.

Berlaku untuk

Lihat juga