Gewusst wie: Festlegen von Optionen mit CheckBox-Steuerelementen in Windows Forms

Aktualisiert: November 2007

In Windows Forms dienen CheckBox-Steuerelemente dazu, dem Benutzer die Auswahl zwischen True/False bzw. Ja/Nein zu bieten. Wenn das Steuerelement aktiviert ist, wird ein Häkchen angezeigt.

So legen Sie Optionen mit CheckBox-Steuerelementen fest

  • Stellen Sie den Zustand der Checked-Eigenschaft fest, indem Sie ihren Wert prüfen. Legen Sie mithilfe dieses Werts eine Option fest.

    Wenn das CheckedChanged-Ereignis des CheckBox-Steuerelements ausgelöst wird, wird im folgenden Codebeispiel die AllowDrop-Eigenschaft des Formulars auf false festgelegt, sofern das Kontrollkästchen aktiviert ist. Dies empfiehlt sich, wenn Sie die Benutzerinteraktion einschränken möchten.

    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;
          }
       }
    

Siehe auch

Aufgaben

Gewusst wie: Reagieren auf das Klicken auf Kontrollkästchen in Windows Forms

Referenz

Übersicht über das CheckBox-Steuerelement (Windows Forms)

CheckBox

Weitere Ressourcen

CheckBox-Steuerelement (Windows Forms)