登录框记住账号

构造函数部分:

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();
}
}

原文地址:https://www.cnblogs.com/m110/p/7902562.html