繁体   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