Chinaunix首页 | 论坛 | 博客
  • 博客访问: 512004
  • 博文数量: 88
  • 博客积分: 2256
  • 博客等级: 大尉
  • 技术积分: 921
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-08 23:20
个人简介

积硅步,行千里

文章分类

全部博文(88)

文章存档

2019年(5)

2018年(1)

2016年(15)

2015年(23)

2013年(3)

2012年(6)

2011年(3)

2010年(22)

2009年(10)

我的朋友

分类: C#/.net

2015-05-06 14:36:31

在txtusername的keyPress下作如下事件
  1. ///
  2.             ///用户名按钮事件(登录读取文件)
  3.             ///
  4.             string s = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  5.             string path =s+"user.dll";
  6.             //string path = @"D:\user.txt";
  7.             if(File.Exists(path))//路径和文件类型
  8.             {
  9.                 StreamReader sr = new StreamReader(path,true);
  10.                 string str = sr.ReadLine();
  11.                 while(str!=null)//判断不为空行
  12.                 {
  13.                     if(!this.UserName.AutoCompleteCustomSource.Contains(str)) //是否包含在集里面
  14.                     {
  15.                         this.UserName.AutoCompleteCustomSource.Add(str); //如果不包含就添加进去
  16.                     }
  17.                     str = sr.ReadLine();
  18.                 }
  19.                 sr.Close();
  20.             }

在登录成功后加入如下事件:
  1. //将登录成功的用户名记录到文本框中,方便下次输入
  2.                         string s = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
  3.                         string path = s + "user.dll";
  4.                         FileStream fs = null;
  5.                         if (File.Exists(path))//判断文件存在
  6.                         {
  7.                             if (!this.UserName.AutoCompleteCustomSource.Contains(this.UserName.Text))
  8.                             {
  9.                                 StreamWriter sw = new StreamWriter(path, true);//true参数不可少,否则会覆盖以前的记录
  10.                                 sw.WriteLine(this.UserName.Text.Trim());//存入记录
  11.                                 sw.Close();
  12.                                 if (!this.UserName.AutoCompleteCustomSource.Contains(this.UserName.Text))
  13.                                 {
  14.                                     this.UserName.AutoCompleteCustomSource.Add(this.UserName.Text);
  15.                                 }
  16.                             }
  17.                         }



阅读(1333) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~