Nasıl yapılır: Windows Forms CheckBox Denetimleriyle Seçenekleri Ayarlama

Kullanıcılara Windows/Yanlış veya Evet/Hayır seçenekleri vermek için bir Windows CheckBox Forms denetimi kullanılır. Denetim seçildiğinde bir onay işareti görüntüler.

CheckBox denetimleriyle seçenekleri ayarlamak için

  1. Durumunu belirlemek için Checked özelliğinin değerini inceler ve bu değeri kullanarak bir seçenek ayarlayın.

    Aşağıdaki kod örneğinde, denetimin olayı lendiğinde, onay kutusu işaretli ise formun CheckBox CheckedChanged özelliği olarak AllowDrop false ayarlanır. Bu, kullanıcı etkileşimini kısıtlamak istediğiniz durumlar için kullanışlıdır.

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

Ayrıca bkz.