110,534
社区成员
发帖
与我相关
我的任务
分享
if (File.Exists(@"../../XX.txt"))//路径和文件类型大家自己设置
{
StreamReader sr = new StreamReader(@"../../XX.txt", true);
string str = sr.ReadLine();
if (str != null)
{
txtAA.Text = str.Trim();
}
sr.Close();
}
if (File.Exists("路径/XX.txt"))
{
if (!this.txtAA.AutoCompleteCustomSource.Contains(txtAA.Text))//判断记录是否存在
{
StreamWriter sw = new StreamWriter("路径/XX.txt", false);//true参数不可少,否则会覆盖以前存入的记录
sw.WriteLine(this.txtAA.Text.Trim());//存入记录
sw.Close();
if (!this.txtAA.AutoCompleteCustomSource.Contains(this.txtAA.Text))
{
this.txtAA.AutoCompleteCustomSource.Add(this.txtAA.Text);
}
}
this.DialogResult = DialogResult.OK;
}