且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SharedPreferences 但在 c# Windows 窗体应用程序 C# Visual Studio

更新时间:2023-10-11 09:03:16

在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;
}