[英]How to uncheck a checkbox?
Checkbox1 calls photoshop to create pictures to a folder. Checkbox1调用photoshop将图片创建到文件夹。 The code below checks a file in the folder to see if a ID# is present, the ID# is created everytime photoshop creates pictures.
下面的代码检查文件夹中的文件,以查看是否存在ID#,每次Photoshop创建图片时都会创建ID#。 If the ID# is present it shows a message box saying that the pictures are present and ask the user do they want to replace the pictures.
如果存在ID#,则会显示一个消息框,说明存在图片,并询问用户是否要替换图片。
private void PicCheck()
{
if (Checkbox1.Checked == true)
{
if (File.Exists("path/text.cde"))
{
string text = File.ReadAllText("path/text.cde");
bool present = text.IndexOf("ID#??") >= 0;
if (present == true)
{
MessageBox.Show("Pictures exist, Replace??", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (DialogResult == DialogResult.No)
{
Checkbox1.Checked = false;
}
}
else
{
File.WriteAllText("path/text.cde", ("ID#??"));
}
}
}
}
My Problem is that when the ID# is present and the user press No the checkbox doesnt get unchecked and the pictures are created again anyway. 我的问题是,当存在ID#并且用户按No时,该复选框不会被取消选中,并且无论如何都将再次创建图片。 What I need is when the user press no, checkbox1 is deselected and the photoshop process assigned to checkbox1 is skipped.
我需要的是,当用户按no时,取消选中checkbox1,并且跳过了分配给checkbox1的photoshop进程。 Is this possible?
这可能吗? Note: It does this check after the user checked checkbox1 and pressed the create button.
注意:在用户选中checkbox1并按下创建按钮后,它将执行此检查。
Any help would be appreciated and thank you in advance. 任何帮助将不胜感激,并提前感谢您。
You need to assign the result of the Show
method to see whether they have pressed yes or no: 您需要分配
Show
方法的结果,以查看它们是否按了yes或no:
DialogResult dialogResult = MessageBox.Show("Pictures exist, Replace??", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.No)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.