【发布时间】:2015-09-30 19:52:11
【问题描述】:
我有这个代码,但是当我运行程序时仍然被阻止。使用此代码,我想检查/取消选中所有项目,并且当在文本文件 installer.ini 中检查以写入 #product=name of checkbox => product=name of checkbox 并且如果在我有 product=name of checkbox 替换为的文本文件中未选中它#product=name of checkbox.
private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
string installerfilename = path + "installer.ini";
string installertext = File.ReadAllText(installerfilename);
var lin =File.ReadLines(path + "installer.ini").ToArray();
CheckBox cb = sender as CheckBox;
if (cb.Checked)
{
for (int i = 0; i < this.checkedListBox2.Items.Count; i++)
{
this.checkedListBox2.SetItemChecked(i, true);
foreach (var txt in lin)
{
if (txt.Contains("#product="))
{
var name = txt.Split('=')[1];
installertext = installertext.Replace("#product=", "product=" + name);
}
File.WriteAllText(installerfilename, installertext);
}
}
}
else if (!cb.Checked)
{
for (int i = 0; i < this.checkedListBox2.Items.Count; i++)
{
this.checkedListBox2.SetItemChecked(i, false);
foreach (var txt in lin)
{
if (txt.Contains("product="))
{
var name1 = txt.Split('=')[1];
installertext = installertext.Replace("product=", "#product=" + name1);
}
File.WriteAllText(installerfilename, installertext);
}
}
}
}
【问题讨论】:
-
“程序被阻止”是什么意思?你有什么例外吗?
-
这段代码写在文本文件行中或者现在当我运行复选框时仍然被阻止..我不知道什么是粗糙的
-
我只想用 product=..... 替换 #product= ...... 如果选中了复选框,如果不替换 product=..... with #product=...... 当我尝试检查和取消选中所有项目时,但当我尝试写入文本文件时不起作用