我接下来需要做的是删除创建到INI中的数据并重新编号面板,删除工作但我似乎没有弄清楚如何重新编号面板,这里是个主意。我的应用程序正在制作一个INi文件,保存这样的数据:
[Panel - 1]
Name=A name
Link=A link
[PanelCount]
Count=3
[Panel - 2]
Name=B name
Link=B link
[Panel - 3]
Name=C name
Link=C link
现在如果我删除例如Panel 2,我会得到这样的结果:
[Panel - 1]
Name=A name
Link=A link
[PanelCount]
Count=2
[Panel - 3]
Name=C name
Link=C link
计数表格PanelCount正在减少,但面板现在是1和3,我想修改所有比我删除的更多的内容。
我想让PanelCount选项卡永远保持最后,似乎它总是因为某种原因而排在第二位。
我想得到的是:
[Panel - 1]
Name=A name
Link=A link
[Panel - 2]
Name=C name
Link=C link
[PanelCount]
Count=2
这是Write C代码:
public void Write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value, this.filePath);
}
private void button1_Click(object sender, EventArgs e)
{
INIFile ini = new INIFile("config.ini");
Int32.TryParse(ini.Read("PanelCount", "Count"),out i);
int panelCount = flowLayoutPanel1.Controls.Count-1;
if(f2.Ok == true)
{
ini.Write("Panel - " + i, "Name", laB.Text);
ini.Write("Panel - " + i, "Link", laB.Name);
ini.Write("PanelCount", "Count", panelCount.ToString());
}
}
以下是我尝试过这项工作的原因:
public string Read(string section, string key)
{
StringBuilder SB = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", SB, 255, this.filePath);
return SB.ToString();
}
private void picB_DoubleClick(object sender, EventArgs e)
{
string del = flp.Name;
INIFile ini = new INIFile("config.ini");
int PanelCount = int.Parse(ini.Read("PanelCount", "Count"));
int count = PanelCount;
//ini.DeleteSection("Panel - " + del);
int loc = 0;
//int.TryParse(del, out loc);
count--;
for (int i = 1; i <= loc;i++ )
{
//ini.Write("Panel - " + del);
}
ini.Write("PanelCount", "Count", count.ToString());
}