Visual C#-属性.设置赢得';无法正确保存
我正在制作一个程序,将鼠标X和鼠标Y坐标从NumericUpDown框保存到Settings.Settings中,这样程序就可以用最后使用的值启动 当“ValueChanged”时,两个输入框都调用方法“saveXY” 我的问题是:X坐标保存没有问题,Y坐标根本没有保存-但代码是一样的:Visual C#-属性.设置赢得';无法正确保存,c#,visual-studio,numericupdown,settings.settings,C#,Visual Studio,Numericupdown,Settings.settings,我正在制作一个程序,将鼠标X和鼠标Y坐标从NumericUpDown框保存到Settings.Settings中,这样程序就可以用最后使用的值启动 当“ValueChanged”时,两个输入框都调用方法“saveXY” 我的问题是:X坐标保存没有问题,Y坐标根本没有保存-但代码是一样的: private void Form1_Load(object sender, EventArgs e) { movetoX.Value = Settings.Default.mo
private void Form1_Load(object sender, EventArgs e)
{
movetoX.Value = Settings.Default.mouseX;
movetoY.Value = Settings.Default.mouseY;
}
-
这些是我的
.exe是可用的。本文可能对您有用 更新1: 必须执行Properties.Settings.Default.Upgrade(),然后加载保存的设置。 样本
多亏了哈米克斯,它现在可以工作了 我删除了saveXY并写了以下内容:
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Settings.Default.mouseX = (int)movetoX.Value;
Settings.Default.mouseY = (int)movetoY.Value;
Settings.Default.Save();
}
现在它可以保存X和Y了你说的“不保存”是什么意思?你是否从visual studio运行你的应用程序?我按Strg+F5运行它,mouseX保存在Settings.Settings中,但不是MouseY,这是用于测试的.exe:我看到你从另一个线程更新你的UI。我不确定为什么你的应用程序没有得到异常。不要使用线程classmy one values saves,但我的其他价值观并没有保存:/——我不知道为什么
public Form1()
{
InitializeComponent();
//Load saved settings
this.Location = Properties.Settings.Default.Form1Location;
this.Size = Properties.Settings.Default.Form1Size;
//Allow changes to be implemented
this.StartPosition = FormStartPosition.Manual;
//capture changes
this.LocationChanged += new EventHandler(Form1_LocationChanged);
this.SizeChanged += new EventHandler(Form1_SizeChanged);
//capture the closing form event to save your new settings
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
}
void Form1_LocationChanged(object sender, EventArgs e)
{
//Capture the new values
Properties.Settings.Default.Form1Location = this.Location;
}
void Form1_SizeChanged(object sender, EventArgs e)
{
//Capture the new values
Properties.Settings.Default.Form1Size = this.Size;
}
void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//you can capture the new values here as well
//save the new values
Properties.Settings.Default.Save();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Settings.Default.mouseX = (int)movetoX.Value;
Settings.Default.mouseY = (int)movetoY.Value;
Settings.Default.Save();
}