다음을 통해 공유


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

업데이트: 2007년 11월

Windows Forms CheckBox 컨트롤은 사용자에게 True/False 또는 Yes/No 옵션을 제공하기 위해 사용합니다. 옵션을 선택하면 확인란에 확인 표시가 나타납니다.

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

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

참고 항목

작업

방법: Windows Forms CheckBox 클릭에 응답

참조

CheckBox 컨트롤 개요(Windows Forms)

CheckBox

기타 리소스

CheckBox 컨트롤(Windows Forms)