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.
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.