Condividi tramite


Procedura: Impostare opzioni con i controlli CheckBox di Windows Form

Un controllo CheckBox Windows Form viene usato per offrire 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 proprietà Checked per determinarne lo stato e usare tale valore per impostare un'opzione.

    Nell'esempio di codice riportato di seguito, quando viene attivato l'evento CheckBox del controllo CheckedChanged, la proprietà AllowDrop del modulo viene impostata su false se è selezionata la casella di controllo. 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;
          }
       }
    

Vedere anche