Share via


CheckBox.ThreeState Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah CheckBox akan mengizinkan tiga status pemeriksaan daripada dua.

public:
 property bool ThreeState { bool get(); void set(bool value); };
public bool ThreeState { get; set; }
member this.ThreeState : bool with get, set
Public Property ThreeState As Boolean

Nilai Properti

trueCheckBox jika mampu menampilkan tiga status pemeriksaan; jika tidak, false. Nilai defaultnya adalah false.

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. Kode ini mengharuskan , CheckBoxLabel 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

ThreeState Jika properti diatur ke false, CheckState nilai properti hanya dapat diatur ke Indeterminate nilai System.Windows.Forms.CheckState dalam kode dan bukan oleh interaksi pengguna.

Berlaku untuk