我正在创建一个程序,将NumericUpDown-Box中的Mouse X和Mouse Y坐标保存到Settings.settings中,以便程序以最后使用的值启动。
当“ValueChanged”as seen here
时,两个输入框都会调用方法“saveXY”我的问题是:X坐标保存没有问题,Y坐标根本没有保存 - 但代码是相同的:
private void Form1_Load(object sender, EventArgs e)
{
movetoX.Value = Settings.Default.mouseX;
movetoY.Value = Settings.Default.mouseY;
}
-
private void saveXY(object sender, EventArgs e)
{
Settings.Default.mouseX = (int)movetoX.Value;
Settings.Default.mouseY = (int)movetoY.Value;
Settings.Default.Save();
}
Theese是我的Settings.settings。
.exe是可用的here。
答案 0 :(得分:0)
这篇文章可能对您有用。 http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx
更新1:
必须执行Properties.Settings.Default.Upgrade(),然后才能加载已保存的设置。
<强>示例强>
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();
}
答案 1 :(得分:0)
感谢hamix,现在正在工作
我删除了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