CheckBox.Checked Proprietà

Definizione

Ottiene o imposta un valore che indica se l'oggetto CheckBox è nello stato selezionato.

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

Valore della proprietà

true se l'oggetto CheckBox è nello stato selezionato; in caso contrario, false. Il valore predefinito è false.

Nota: se la proprietà è impostata su , la ThreeStateChecked proprietà restituirà true per un Checked oggetto o IndeterminateCheckState.true

Attributi

Esempio

Nell'esempio di codice seguente vengono visualizzati i valori di tre proprietà in un'etichetta. La ThreeState proprietà si alterna tra true e false con clic alternati del controllo e le CheckAlign alternative tra un ContentAlignment valore di MiddleRight e MiddleLeft. In questo esempio viene illustrato come cambiano i valori delle proprietà durante la modifica della ThreeState proprietà e viene controllato il controllo. In questo esempio è necessario che un oggetto e LabelButton che sia stata creata un'istanza di un CheckBoxmodulo e che l'etichetta System.Drawing sia abbastanza grande per visualizzare tre righe di testo, nonché un riferimento allo spazio dei nomi. Questo codice deve essere chiamato nel Click gestore eventi del controllo.

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

Commenti

Quando il valore è true, la CheckBox parte del controllo visualizza un segno di spunta. Se la Appearance proprietà è impostata su Button, il controllo apparirà incassato quando Checked viene true generato come un pulsante standard quando false.

Si applica a

Vedi anche