Partager via


CheckBox.Checked Propriété

Définition

Obtient ou définit une valeur indiquant si l’état CheckBox est vérifié.

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

Valeur de propriété

true si l’état CheckBox est vérifié ; sinon, false. La valeur par défaut est false.

Remarque : Si la ThreeState propriété est définie truesur , la Checked propriété est retournée true pour une Checked ou IndeterminateCheckState.

Attributs

Exemples

L’exemple de code suivant affiche les valeurs de trois propriétés dans une étiquette. La ThreeState propriété alterne entre true et false avec des clics alternés du contrôle et les CheckAlign alternatives entre une ContentAlignment valeur et MiddleRightMiddleLeft. Cet exemple montre comment les valeurs de propriété changent à mesure que la ThreeState propriété change et que le contrôle est vérifié. Cet exemple nécessite qu’un CheckBox, Label et Button tous ont été instanciés sur un formulaire et que l’étiquette est suffisamment grande pour afficher trois lignes de texte, ainsi qu’une référence à l’espace System.Drawing de noms. Ce code doit être appelé dans le Click gestionnaire d’événements du contrôle.

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

Remarques

Lorsque la valeur est true, la CheckBox partie du contrôle affiche une coche. Si la Appearance propriété est définie Buttonsur , le contrôle s’affiche quand Checked est true et déclenché comme un bouton standard quand false.

S’applique à

Voir aussi