登录框记住账号

构造函数部分:

StreamReader sr = new StreamReader("nb.abc");
string[] sss = sr.ReadToEnd().Split('|');

foreach (string s in sss)
{
if (s.Length > 0)
{
comboBox1.Items.Add(s);
}
}
if (comboBox1.Items.Count > 0)
{
comboBox1.SelectedIndex = 0;
}
sr.Dispose();

 

方法部分:

if (checkBox1.Checked)
{
StreamReader sr = new StreamReader("nb.abc");
string names = sr.ReadToEnd();
sr.Dispose();

if (!names.Contains(u.UserName))
{
StreamWriter sw = new StreamWriter("nb.abc");
sw.Write(u.UserName + "|" + names);
sw.Flush();
sw.Dispose();
}
}

 

posted on 2017-11-27 08:53  段了的弦  阅读(186)  评论(0编辑  收藏  举报