Skip to main content
 首页 » 编程设计

c#之如果选中复选框,请执行其他操作取消选中

2024年02月13日14cloudgamer

我正在尝试创建一个 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; 
}