using System;
using System.Windows.Forms;
namespace TestPr12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.SelectedIndex = 0;
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(textBox1.Text);
textBox1.Clear();
}
}
}
private const string FILE = "C:\\savedata.txt";
public Form1()
{
InitializeComponent();
comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
if (File.Exists(FILE)){
IFormatter f = new BinaryFormatter();
var fs = new FileStream(FILE, FileMode.Open, FileAccess.ReadWrite);
var data = (List<string>) f.Deserialize(fs);
comboBox1.Items.AddRange(data.ToArray());
fs.Close();
}
}
protected override void OnClosing(CancelEventArgs e)
{
IFormatter f = new BinaryFormatter();
var data = comboBox1.Items.Cast<string>().ToList();
var fs = new FileStream(FILE, FileMode.Create, FileAccess.ReadWrite);
f.Serialize(fs, data);
fs.Close();
}