Comment : définir des options avec les contrôles CheckBox 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 marque case activée lorsqu’il est sélectionné.

Pour définir des options avec des contrôles CheckBox

  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 CheckedChanged contrôle est déclenché, la propriété du AllowDrop formulaire est définie false si la zone case activée est case activée ed. 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