Partager via


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

Un contrôle Windows Forms CheckBox est utilisé pour donner aux utilisateurs les options True/False ou Oui/Non. Le contrôle affiche une coche lorsqu’il est sélectionné.

Pour définir des options avec des contrôles de case à cocher

  1. Examinez la valeur de la Checked propriété pour déterminer son état et utilisez cette valeur pour définir une option.

    Dans l’exemple de code ci-dessous, lorsque l’événement CheckBox du contrôle CheckedChanged est levé, la propriété AllowDrop du formulaire est définie à false si la case à cocher est cochée. Cela est utile pour les situations où vous souhaitez restreindre l’interaction 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->CheckState == CheckState::Checked)
          {
             // If checked, do not allow items to be dragged onto the form.
             this->AllowDrop = false;
          }
       }
    

Voir aussi