问题
I'm creating a simple messages program, in which u can talk to other people.
Currently, I'm working on the login screen and I want to create a "remember me" option which will save your credentials the next time u enter the app. I worked a bit with android Studio,and Unity, and they both use something called SharedPreferences
, I used it and it's great. So I wanna know if there is a SharedPreferences
for C# and how to use it on a Windows Form App.
Any help is accepted.
回答1:
In winforms, we usually use Settings
to keep the user setting info.
To achieve the requirement, you can refer to the following steps:
1.Click "Project" and choose "Setting Properties…", then choose "Settings"
2.Add new setting in "Settings"
3.Try the following code:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// Save the current state of the checkbox
Properties.Settings.Default.cb = checkBoxRememberMe.Checked;
Properties.Settings.Default.str = textBox1.Text;
Properties.Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
// load checkbox state from settings
checkBoxRememberMe.Checked = Properties.Settings.Default.cb;
textBox1.Text = Properties.Settings.Default.str;
}
来源:https://stackoverflow.com/questions/65142729/sharedpreferences-but-on-c-sharp-windows-form-apps-c-sharp-visual-studio