我有一個帶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保存/加載數據。 –
對不起,我不清楚。按鈕移動得很好。我無法保存位置。 –
那麼,顯示你的保存代碼。 –