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 属性将返回 trueCheckedIndeterminateCheckState

属性

示例

下面的代码示例显示标签中三个属性的值。 属性ThreeState在 和 false 之间true交替单击控件CheckAlign,在 值MiddleRightMiddleLeft之间ContentAlignment交替单击。 此示例演示属性值如何随着 ThreeState 属性更改和控件的检查而更改。 此示例要求 CheckBox在窗体上实例化 和 ButtonLabel ,并且标签足够大,以显示三行文本,以及对 命名空间的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

注解

当 值为 时trueCheckBox控件的部分将显示检查标记。 如果 属性Appearance设置为 Button,则 控件将在 时Checkedtrue显示为凹陷,并在 时false像标准按钮一样引发。

适用于

另请参阅