我有一个带10个小按钮(20 x 20)的用户控件。我正在使用以下代码来允许用户只沿x轴拖动每个按钮。 然后我想将它的X位置保存到一个列表中,该列表可以保存为XML文件的一部分,然后在下次运行应用程序时加载相同的按钮位置。出于某种原因,我无法保存按钮位置。即使消息框不显示。我究竟做错了什么?无法将按钮位置保存在XML文件中
private Point p;
private void button2_mousedown(object sender, MouseEventArgs e)
{
string buttonName = ((Button)sender).Name;
Button b1 = ((Button)sender);
if (e.Button == MouseButtons.Left)
{
p = e.Location;
}
}
private void button2_mousemove(object sender, MouseEventArgs e)
{
string buttonName = ((Button)sender).Name;
Button b1 = ((Button)sender);
if (e.Button == MouseButtons.Left)
{
b1.Left = e.X + b1.Left - p.X;
}
int idx = int.Parse(buttonName) - 1;
scriptIconLocation[idx] = b1.Left;
//MessageBox.Show(scriptIconLocation[idx].ToString(), "saved location");
savedSettings.ScriptIconLocation = scriptIconLocation;
saveSettingsXML(savedSettings);
}
您必须提出两个不同的问题。首先关于按钮的移动,其次是关于从xml保存/加载数据。 –
对不起,我不清楚。按钮移动得很好。我无法保存位置。 –
那么,显示你的保存代码。 –