CheckBox.Checked 屬性

定義

取得或設定值,指出 CheckBox 是否在已核取狀態下。

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

屬性值

如果 CheckBox 處於已核取狀態,則為 true,否則為 false。 預設值是 false

注意:如果 ThreeState 屬性設定 true 為 ,則 Checked 屬性會針對 Checked 或 傳 IndeterminateCheckStatetrue

屬性

範例

下列程式碼範例會顯示標籤中三個屬性的值。 屬性會 ThreeStatetruefalse 以 控制項的替代點選和 和 之間的替代方式,以及 CheckAlignMiddleRightMiddleLeft 之間的 ContentAlignment 替代專案。 本範例示範屬性值如何隨著屬性變更而變更 ThreeState ,並檢查控制項。 這個範例要求 CheckBox 在表單上具現化 和 LabelButton ,而且標籤夠大,足以顯示三行文字,以及命名空間的 System.Drawing 參考。 此程式碼應該在 控制項的事件處理常式中 Click 呼叫。

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

備註

當值為 true 時, CheckBox 控制項的部分會顯示核取記號。 Appearance如果 屬性設定 Button 為 ,當 為 trueChecked ,控制項會出現下陷,並在 時引發,就像標準按鈕一 false 樣。

適用於

另請參閱