开发者

Save user settings in c#

i try to save user settings in 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:

    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:

Save user settings in c#

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜