我尝试使用此代码加载和保存设置但是当我关闭并重新运行程序时未加载的设置。默认情况下,设置为空白。我没有错误。
private void Form1_Load(object sender, EventArgs e)
{
txtUsername.Text = Properties.Settings.Default.Username;
txtPassword.Text = Properties.Settings.Default.Password;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Username = txtUsername.Text;
Properties.Settings.Default.Password = txtPassword.Text;
}
答案 0 :(得分:6)
试
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.Username = txtUsername.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.Save();
}
答案 1 :(得分:3)
How To: Write User Settings at Run Time with C# 如果要在应用程序会话之间保留对设置的更改,请调用Save方法,如下所示:;
Properties.Settings.Default.Save();
您需要在Form1_FormClosing