簡體   English   中英

如果復選框選中做其他事情取消選中

[英]If checkbox checked do something else uncheck

我正在嘗試創建一個 if 語句來提示我詢問我是否確定要選中復選框。 如果復選框已經被選中,只需取消選中該框。 以下是我似乎無法開始工作的內容。 謝謝! 如果有人有這樣做的簡單方法,請提供建議。

if (checkBox15.Checked == false)
{
    MessageBox.Show("Are you sure you want to check this?", "Prompt", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
    { 
        Updatelist(); 
    } 
    else
    {
        checkBox15.Checked = false;
        return;
    }  
}
else  if (checkBox15.Checked == true)
{
    checkBox15.Checked = false;
    return;
} 

你錯過了if(

if(MessageBox.Show("Are you sure you want to check this?", 
    "Prompt", 
    MessageBoxButtons.YesNo, 
    MessageBoxIcon.Question) == DialogResult.Yes)
{ 
    Updatelist(); 
}
else
{
    checkBox15.Checked = false;
    return;
}  

這是你的答案

if (checkBox15.IsEnabled == false)
{
MessageBox.Show("Are you sure you want to check this?", "Prompt",    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ 
    Updatelist(); 
} 
else
{
    checkBox15.IsEnabled = false;
    return;
}  
}`enter code here`
else  if (checkBox15.IsEnabled == true)
{
checkBox15.Checked = false;
return;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM