c#中保存用户选项

本文关键字:用户选项 保存 | 更新日期: 2023-09-27 18:12:03

我看了一些教程,没有一个是不工作的…我甚至在2010年从2015年改变了我的Visual Studio,没有工作…

这就是代码:

private void button1_Click(object sender, EventArgs e)
{
    WindowsFormsApplication3.Properties.Settings.Default.label = label1.Text;
    WindowsFormsApplication3.Properties.Settings.Default.Save();
}
private void Form1_Load(object sender, EventArgs e)
{
    label1.Text = WindowsFormsApplication3.Properties.Settings.Default.label;
}

在label1应用程序设置中,我做了一个设置:

name: label;类型:字符串;经营范围:用户;

当我在程序中按下按钮时,绝对没有任何事情发生:|

c#中保存用户选项

我想你对应该发生的事情的期望可能有点错误

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
        WindowsFormsApplication1.Properties.Settings.Default.Label = label1.Text + "!";//change the value
        WindowsFormsApplication1.Properties.Settings.Default.Save(); //save the change
        WindowsFormsApplication1.Properties.Settings.Default.Reload(); //instruct the form to reload the settings from the file
        label1.Text = WindowsFormsApplication1.Properties.Settings.Default.Label; //update the label text to show the change
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        label1.Text = WindowsFormsApplication1.Properties.Settings.Default.Label; // set the initial value
    }