我试图使用此代码加载和保存设置,但是当我关闭并重新运行程序时,未加载设置。默认情况下,设置为空白。我没有错。

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

最佳答案

尝试

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  Properties.Settings.Default.Username = txtUsername.Text;
  Properties.Settings.Default.Password = txtPassword.Text;
  Properties.Settings.Default.Save();
}

关于c# - C#设置加载和保存,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11238398/

10-16 16:09