CheckBox.Checked Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta un valore che indica se è 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 è CheckBox nello stato selezionato; in caso contrario, false. Il valore predefinito è false.
Nota: se la ThreeState proprietà è impostata su true, la Checked proprietà restituirà true per un Checked oggetto o IndeterminateCheckState.
- 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 i valori delle proprietà cambiano man mano che la ThreeState proprietà cambia e il controllo viene controllato. Questo esempio richiede che sia CheckBoxLabel stata creata un'istanza di e Button in una maschera e che l'etichetta sia sufficientemente grande da visualizzare tre righe di testo, nonché un riferimento allo spazio dei System.Drawing 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 verrà visualizzato incassato quando Checked viene true generato come un pulsante standard quando false.