Condividi tramite


Procedura: impostare opzioni con i controlli CheckBox di Windows Form

Aggiornamento: novembre 2007

Il controllo CheckBox di Windows Form viene utilizzato per consentire agli utenti di scegliere tra le opzioni Vero/Falso o Sì/No. Una volta effettuata la selezione, il controllo visualizzerà un segno di spunta.

Per impostare le opzioni con i controlli CheckBox

  • Verificare il valore della proprietà Checked per determinarne lo stato e utilizzare tale valore per impostare un'opzione.

    Nell'esempio di codice riportato di seguito, quando viene generato l'evento CheckedChanged del controllo CheckBox, la proprietà AllowDrop del form viene impostata su false se la casella di controllo è selezionata. Questa funzione è utile per le situazioni in cui si desidera 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.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;
          }
       }
    

Vedere anche

Attività

Procedura: rispondere alla selezione di controlli CheckBox Windows Form

Riferimenti

Cenni preliminari sul controllo CheckBox (Windows Form)

CheckBox

Altre risorse

Controllo CheckBox (Windows Form)