CheckBox.Checked Propiedad

Definición

Obtiene o establece un valor que indica si CheckBox está en el estado activado.

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

Valor de propiedad

true si el control CheckBox se encuentra en estado seleccionado; en caso contrario, es false. El valor predeterminado es false.

Nota: Si la ThreeState propiedad está establecida trueen , la Checked propiedad devolverá true para o IndeterminateCheckedCheckState.

Atributos

Ejemplos

En el ejemplo de código siguiente se muestran los valores de tres propiedades de una etiqueta. La ThreeState propiedad alterna entre true y false con clics alternativos del control y las CheckAlign alternativas entre un ContentAlignment valor de MiddleRight y MiddleLeft. En este ejemplo se muestra cómo cambian los valores de propiedad a medida que cambia la ThreeState propiedad y se comprueba el control. En este ejemplo se requiere que CheckBoxLabel se haya creado una instancia de y Button en un formulario y que la etiqueta sea lo suficientemente grande como para mostrar tres líneas de texto, así como una referencia al System.Drawing espacio de nombres. Se debe llamar a este código en el Click controlador de eventos del control .

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

Comentarios

Cuando el valor es true, la CheckBox parte del control muestra una marca de verificación. Si la Appearance propiedad se establece Buttonen , el control aparecerá hundido cuando Checked sea true y se genere como un botón estándar cuando false.

Se aplica a

Consulte también