private void Form1_Load(object sender, EventArgs e) { if (File.Exists(path) && MessageBox.Show("Загрузить предыдущие сохраненные параметры?", "Загрузка", MessageBoxButtons.YesNo) == DialogResult.Yes) { INIManager manager = new INIManager(path); textBox1.Text = manager.GetPrivateString("InputTextBox", "value"); int count = int.Parse(manager.GetPrivateString("ListBox", "count")); for (int i = 0; i < count; i++) { listBox1.Items.Add(manager.GetPrivateString("ListBox", $"line{i}")); } } comboBox1.Text = "Добавить"; FileInfo fi1 = new FileInfo(path); if (!File.Exists(path)) { using (StreamWriter sw = fi1.CreateText()); } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Сохранить данные полей?", "Сохранение", MessageBoxButtons.YesNo) == DialogResult.Yes) { File.WriteAllText(path, string.Empty); INIManager manager = new INIManager(path); manager.WritePrivateString("ListBox", $"count", listBox1.Items.Count.ToString()); for (int i = 0; i < listBox1.Items.Count; i++) { manager.WritePrivateString("ListBox", $"line{i}", listBox1.Items[i].ToString()); } manager.WritePrivateString("InputTextBox", "value", textBox1.Text); } }