[英]SharedPreferences but on c# Windows Form Apps C# Visual Studio
我正在创建一个简单的消息程序,您可以在其中与其他人交谈。
目前,我正在登录屏幕上工作,我想创建一个“记住我”选项,它将在您下次进入应用程序时保存您的凭据。 我使用 android Studio 和 Unity 进行了一些工作,它们都使用了名为SharedPreferences
的东西,我使用了它,它很棒。 所以我想知道 C# 是否有SharedPreferences
以及如何在 Windows 表单应用程序上使用它。
接受任何帮助。
在winforms中,我们通常使用Settings
来保存用户设置信息。
要达到要求,可以参考以下步骤:
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.