Porady: ustawianie opcji za pomocą formantów CheckBox formularzy systemu Windows

Kontrolka Formularze systemu CheckBox Windows służy do nadawania użytkownikom opcji Prawda/Fałsz lub Tak/Nie. Kontrolka wyświetla znacznik wyboru po jej wybraniu.

Aby ustawić opcje za pomocą kontrolek CheckBox

  1. Sprawdź wartość Checked właściwości, aby określić jej stan, i użyj tej wartości, aby ustawić opcję.

    W poniższym przykładzie kodu po CheckBox wystąpieniu zdarzenia kontrolki CheckedChanged właściwość formularza AllowDrop jest ustawiana na false wartość , jeśli pole wyboru jest zaznaczone. Jest to przydatne w sytuacjach, w których chcesz ograniczyć interakcję użytkownika.

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

Zobacz też