Cómo: Establecer opciones con los controles CheckBox de formularios Windows Forms
Actualización: noviembre 2007
El control CheckBox de los formularios Windows Forms se utiliza para ofrecer 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
Examine el valor de la propiedad Checked para determinar su estado y utilice este valor para establecer una opción.
En el ejemplo de código siguiente, cuando se produce el evento CheckedChanged del control CheckBox, la propiedad AllowDrop del formulario se establece en false si se activa la casilla. Esto es útil en situaciones en las que se desee 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.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; } }
Vea también
Tareas
Cómo: Responder a clics en casillas de formularios Windows Forms
Referencia
Información general sobre el control CheckBox (formularios Windows Forms)