在txtusername的keyPress下作如下事件
-
///
-
///用户名按钮事件(登录读取文件)
-
///
-
string s = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
-
string path =s+"user.dll";
-
//string path = @"D:\user.txt";
-
if(File.Exists(path))//路径和文件类型
-
{
-
StreamReader sr = new StreamReader(path,true);
-
string str = sr.ReadLine();
-
while(str!=null)//判断不为空行
-
{
-
if(!this.UserName.AutoCompleteCustomSource.Contains(str)) //是否包含在集里面
-
{
-
this.UserName.AutoCompleteCustomSource.Add(str); //如果不包含就添加进去
-
}
-
str = sr.ReadLine();
-
}
-
sr.Close();
-
}
在登录成功后加入如下事件:
-
//将登录成功的用户名记录到文本框中,方便下次输入
-
string s = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
-
string path = s + "user.dll";
-
FileStream fs = null;
-
if (File.Exists(path))//判断文件存在
-
{
-
if (!this.UserName.AutoCompleteCustomSource.Contains(this.UserName.Text))
-
{
-
StreamWriter sw = new StreamWriter(path, true);//true参数不可少,否则会覆盖以前的记录
-
sw.WriteLine(this.UserName.Text.Trim());//存入记录
-
sw.Close();
-
if (!this.UserName.AutoCompleteCustomSource.Contains(this.UserName.Text))
-
{
-
this.UserName.AutoCompleteCustomSource.Add(this.UserName.Text);
-
}
-
}
-
}
阅读(1379) | 评论(0) | 转发(0) |