SharedPreferences 但在 c# Windows 窗体应用程序 C# Visual Studio [英] 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.
目前,我正在登录屏幕上工作,我想创建一个记住我"选项将在您下次进入应用程序时保存您的凭据.我在 android Studio 和 Unity 上做了一些工作,他们都使用了一种叫做 SharedPreferences
的东西,我用过它,它很棒.所以我想知道 C# 是否有 SharedPreferences
以及如何在 Windows 窗体应用程序上使用它.
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.
接受任何帮助.
推荐答案
在winforms中,我们通常使用Settings
来保存用户设置信息.
In winforms, we usually use Settings
to keep the user setting info.
实现需求,可以参考以下步骤:
To achieve the requirement, you can refer to the following steps:
1.点击项目";并选择设置属性...",然后选择设置"
1.Click "Project" and choose "Setting Properties…", then choose "Settings"
2.在设置"中添加新设置;
2.Add new setting in "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;
}
这篇关于SharedPreferences 但在 c# Windows 窗体应用程序 C# Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!