我正在编写一个简单的应用程序 - 一种在C#中的winforms saper游戏。我的应用程序已经在应用程序设置中保存了一些信息,例如按钮的大小或颜色,但是当我尝试保存自己的结构的数组列表时,出现问题。这是没有错误,但信息不会保存下一个程序execution.Ustawienia是一个公共静态类,其中包括wyniki这是另一种形式,而Properties.Settings.Default.scores是添加到应用程序settigs中的ArrayList。如果您有任何想法我做错了,以及如何在应用程序设置中存储阵列列表,我将不胜感激。在应用程序设置中保存arraylist winforms
下面是代码:
公共部分类Form3:表 {
public Form3()
{
InitializeComponent();
if (Properties.Settings.Default.scores == null)
Properties.Settings.Default.scores = new System.Collections.ArrayList();
}
private void ok_click(object sender, EventArgs e)
{
Highscore higscore = new Highscore(Properties.Settings.Default.ktory, textBox1.Text, ustawienia.ile_wierszy, ustawienia.ile_kolumn, ustawienia.elapsed.Seconds);
Properties.Settings.Default.scores.Add(higscore);
Properties.Settings.Default.scores.Sort(new myComparer());
Properties.Settings.Default.ktory++;
Properties.Settings.Default.Save();
Highscore.show();
this.Close();
}
}
public class Highscore
{
public int nubmer;//w properties ktory=+1;
public string name;
int rows;
int columns;
public int time;
public Highscore(int _number, string _name, int _rows, int _columns, int _time)
{
number = _number;
name = _name;
rows = _rows;
columns = _columns;
time = _time;
}
public static void show()
{
ListView list = (ListView)ustawienia.wyniki.Controls.Find("listView1", true)[0];
list.Items.Clear();
foreach (Highscore e in Properties.Settings.Default.scores)
{
ListViewItem newItem = new ListViewItem(new[] { e.name, e.time.ToString(), e.rows.ToString()+"x"+e.columns.ToString() });
lista.Items.Add(newItem);
}
ustawienia.wyniki.Show();
}
}
public class myComparer:IComparer
{
int IComparer.Compare(Object x, Object y)
{
if (((Highscore)x).time < ((Highscore)y).time)
return 1;
else if (((Highscore)x).time > ((Highscore)y).time)
return -1;
else
{
return String.Compare(((Highscore)x).name,((Highscore)y).name);
}
}
}
}