【问题标题】:Save user settings in c#在c#中保存用户设置
【发布时间】:2011-06-21 18:14:50
【问题描述】:

我尝试在 c# 中保存用户设置。

我可以读取该值并将其放入文本框中,但我无法更改它。

这是我的带有文本框和保存按钮的 WindowsForm:

    namespace tool
{
    public partial class Form4 : Form
    {
        string source = Properties.Settings.Default.Source;
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            textBox1.Text = source;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void save_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Source = source;
            Properties.Settings.Default.Save();
            Application.Exit();
        }
    }
}

这是我设置的图片:

希望有人出主意:-)

感谢您的帮助

【问题讨论】:

    标签: c# settings


    【解决方案1】:

    试试这个:

    private void save_Click(object sender, EventArgs e)
    {
       Properties.Settings.Default.Source = textBox1.Text;
       Properties.Settings.Default.Save();
       Application.Exit();
    }
    

    您需要使用当前文本框中的内容,而不是您的成员变量。

    或者你可以把这个事件改成如下(然后上面的就不用修改了):

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
       source = textBox1.Text;
    }
    

    【讨论】:

      【解决方案2】:

      您是否可以在测试时将读取锁定应用于您正在查看的密钥?也许代码不是问题?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-05
        • 2023-03-27
        • 2021-11-04
        • 1970-01-01
        • 2010-12-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多