Partager via


Comment : définir des options avec les contrôles CheckBox Windows Forms

Mise à jour : novembre 2007

Le contrôle CheckBox Windows Forms permet de proposer à l'utilisateur des alternatives de type Vrai/Faux ou Oui/Non. Il affiche une coche lorsqu'il est sélectionné.

Pour définir des options à l'aide de contrôles CheckBox

  • Lisez la valeur de la propriété Checked pour déterminer son état et servez-vous de cette valeur pour définir une option.

    Dans l'exemple de code ci-dessous, lorsque l'événement CheckedChanged du contrôle CheckBox est généré, la propriété AllowDrop du formulaire prend la valeur false si la case à cocher est activée. Cette particularité est utile lorsque vous souhaitez limiter l'interaction avec l'utilisateur.

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
       ' Determine the CheckState of the check box.
       If CheckBox1.CheckState = CheckState.Checked Then
          ' If checked, do not allow items to be dragged onto the form.
          Me.AllowDrop = False
       End If
    End Sub
    
    private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
    {
       // Determine the CheckState of the check box.
       if (checkBox1.CheckState == CheckState.Checked) 
       {
          // If checked, do not allow items to be dragged onto the form.
          this.AllowDrop = false;
       }
    }
    
    private void checkBox1_CheckedChanged(System.Object sender, System.EventArgs e) 
    {
       // Determine the CheckState of the check box. 
       if ( checkBox1.get_CheckState() == CheckState.Checked  ) 
       {
          // If checked, do not allow items to be dragged onto the form. 
          this.set_AllowDrop(false);
       }
    }
    
    private:
       void checkBox1_CheckedChanged(System::Object ^ sender,
          System::EventArgs ^ e)
       {
          // Determine the CheckState of the check box.
          if (checkBox1->CheckState == CheckState::Checked) 
          {
             // If checked, do not allow items to be dragged onto the form.
             this->AllowDrop = false;
          }
       }
    

Voir aussi

Tâches

Comment : répondre à un clic du contrôle CheckBox Windows Forms

Référence

Vue d'ensemble du contrôle CheckBox (Windows Forms)

CheckBox

Autres ressources

CheckBox, contrôle (Windows Forms)