[英]SharedPreferences but on c# Windows Form Apps C# Visual Studio
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.我使用 android Studio 和 Unity 进行了一些工作,它们都使用了名为
SharedPreferences
的东西,我使用了它,它很棒。 So I wanna know if there is a SharedPreferences
for C# and how to use it on a Windows Form App.所以我想知道 C# 是否有
SharedPreferences
以及如何在 Windows 表单应用程序上使用它。
Any help is accepted.接受任何帮助。
In winforms, we usually use Settings
to keep the user setting info.在winforms中,我们通常使用
Settings
来保存用户设置信息。
To achieve the requirement, you can refer to the following steps:要达到要求,可以参考以下步骤:
1.Click "Project" and choose "Setting Properties…", then choose "Settings" 1.单击“项目”并选择“设置属性...”,然后选择“设置”
2.Add new setting in "Settings" 2.在“设置”中添加新设置
3.Try the following code: 3.试试下面的代码:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.