如何:使用 Windows Form CheckBox 控制項設定選項
Windows Forms CheckBox 控制項可用來為使用者提供 True/False 或 Yes/No 選項。 控制項會在選取時顯示核取記號。
使用 CheckBox 控制項設定選項
檢查 屬性的值 Checked 以判斷其狀態,並使用該值來設定選項。
在下列程式碼範例中,當控制項的事件引發時 CheckBox ,如果核取核取方塊,表單的 AllowDrop 屬性就會設定
false
CheckedChanged 為 。 這適用于您想要限制使用者互動的情況。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; } }
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應