Procedura: impostare opzioni con i controlli CheckBox di Windows Form

Un controllo Windows Form CheckBox viene usato per fornire agli utenti opzioni True/False o Sì/No. Il controllo visualizza un segno di spunta quando è selezionato.

Per impostare le opzioni con i controlli CheckBox

  1. Esaminare il valore della Checked proprietà per determinarne lo stato e usare tale valore per impostare un'opzione.

    Nell'esempio di codice seguente, quando viene generato l'evento CheckBox del CheckedChanged controllo, la proprietà della maschera viene impostata su false se la casella di AllowDrop controllo è selezionata. Ciò è utile per le situazioni in cui si vuole limitare l'interazione dell'utente.

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

Vedi anche