------------------------写txt文件---------------------------------
string fileName = Path.Combine(Application.StartupPath, @"History.txt");
StreamWriter writer = new StreamWriter(fileName,false,Encoding.Default);
foreach (string name in this.userName.AutoCompleteCustomSource)
{
writer.WriteLine(name);
}
writer.Flush();
writer.Close();
------------------------读txt文件---------------------------------
string fileName = Path.Combine(Application.StartupPath, @"History.txt");
if (File.Exists(fileName))
{
StreamReader reader = new StreamReader(fileName,Encoding.Default);
string name = reader.ReadLine();
while (name != null)
{
this.userName.AutoCompleteCustomSource.Add(name);
this.userName.Items.Add(name);
name = reader.ReadLine();
}
reader.Close();
}