在C#中保存用户设置 [英] Save user settings in c#
本文介绍了在C#中保存用户设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将用户设置保存在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.
这是我的WindowsForm,带有一个文本框和一个保存按钮:
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:
我希望有人能提出一个主意:-)
I hope someone as an idea :-)
感谢帮助
推荐答案
尝试一下:
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;
}
这篇关于在C#中保存用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文