简体   繁体   English

如果复选框选中做其他事情取消选中

[英]If checkbox checked do something else uncheck

I am trying to create an if statement to prompt me asking if i am sure i want to check the checkbox.我正在尝试创建一个 if 语句来提示我询问我是否确定要选中复选框。 If the checkbox is already checked to just uncheck the box.如果复选框已经被选中,只需取消选中该框。 Below is what i have an cant seem to get to work.以下是我似乎无法开始工作的内容。 Thanks!谢谢! if anyone has a simple way of doing this please advise.如果有人有这样做的简单方法,请提供建议。

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

You have missed if(你错过了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;
}  

This Is Your Answer这是你的答案

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