[英]Visual C# - Properties.Settings won't save correctly
我正在编写一个程序,将一个NumericUpDown-Box中的Mouse X和Mouse Y坐标保存到Settings.settings中,以便该程序以最后使用的值启动。
两个输入框调用方法“saveXY”当“的ValueChanged” 因为在这里看到
我的问题是:保存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();
}
这些是我的Settings.settings 。
.exe在这里可用。
本文可能对您有用。 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();
}
多亏了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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.