我尝试在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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的设置图片:
我希望有人作为一个想法:-)
感谢帮助
试试这个:
private void save_Click(object sender, EventArgs e)
{
Properties.Settings.Default.Source = textBox1.Text;
Properties.Settings.Default.Save();
Application.Exit();
}
Run Code Online (Sandbox Code Playgroud)
您需要使用文本框中当前的内容,而不是您的成员变量.
或者您可以将此事件更改为如下(然后您不必修改上述内容):
private void textBox1_TextChanged(object sender, EventArgs e)
{
source = textBox1.Text;
}
Run Code Online (Sandbox Code Playgroud)