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.
Visual BasicPrivate 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
C#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; } }
J#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); } }
C++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; } }
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ