共用方式為


如何:使用 Windows Form CheckBox 控制項設定選項

Windows Forms CheckBox 控制項可用來為使用者提供 True/False 或 Yes/No 選項。 控制項會在選取時顯示核取記號。

使用 CheckBox 控制項設定選項

  1. 檢查 屬性的值 Checked 以判斷其狀態,並使用該值來設定選項。

    在下列程式碼範例中,當控制項的事件引發時 CheckBox ,如果核取核取方塊,表單的 AllowDrop 屬性就會設定 falseCheckedChanged 為 。 這適用于您想要限制使用者互動的情況。

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

另請參閱