다음을 통해 공유


방법: Windows Forms CheckBox 컨트롤을 사용하여 옵션 설정

Windows Forms CheckBox 컨트롤은 사용자에게 True/False 또는 Yes/No 옵션을 제공하는 데 사용됩니다. 컨트롤을 선택하면 확인 표시가 표시됩니다.

CheckBox 컨트롤을 사용하여 옵션을 설정하려면

  1. Checked 속성 값을 검사하여 상태를 확인하고 해당 값을 사용하여 옵션을 설정합니다.

    아래 코드 샘플에서 CheckBox 컨트롤의 CheckedChanged 이벤트가 발생하면 확인란이 선택되어 있을 경우 양식의 AllowDrop 속성이 false로 설정됩니다. 이는 사용자 상호 작용을 제한하려는 경우에 유용합니다.

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

참고 항목