简体   繁体   English

在C#中保存用户设置

[英]Save user settings in c#

i try to save user settings in c#. 我尝试将用户设置保存在C#中。

I can read the value and put it in a textbox but i can not change it. 我可以读取该值并将其放在文本框中,但无法更改。

This is my WindowsForm with an textbox and a save button: 这是我的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();
        }
    }
}

And here is a picture with my settings: 这是带有我的设置的图片:

在此处输入图片说明

I hope someone as an idea :-) 我希望有人有想法:-)

Thanks for help 感谢帮助

Try this: 尝试这个:

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

You need to use what is currently in the text box, not your member variable. 您需要使用文本框中当前的内容,而不是您的成员变量。

Or you can change this event to be as follows (and then you don't have to modify the above): 或者,您可以将此事件更改为如下(然后您不必修改以上内容):

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

could you possibly have a read lock being applied to the key you're looking at while testing this? 在测试此键时,是否可以将读锁应用于正在查看的键? Maybe the code's not the problem? 也许代码不是问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM