Share via


Cómo: Establecer opciones con los controles CheckBox de formularios Windows Forms

Un control CheckBox de Windows Forms sirve para proporcionar a los usuarios opciones de tipo Verdadero/Falso o Sí/No. El control muestra una marca de verificación cuando está seleccionado.

Para establecer opciones con controles CheckBox

  1. Examine el valor de la propiedad Checked para determinar su estado y use ese valor para establecer una opción.

    En el ejemplo de código siguiente, cuando se genera el evento CheckedChanged del control CheckBox, la propiedad AllowDrop del formulario se establece en false si la casilla está activada. Esto resulta útil en situaciones en las que se quiere limitar la interacción del usuario.

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

Consulte también