如何将列表框中的项目输入到Settings.Default C#

我试图在Settings.Default中保存列表框中的项目,但它不起作用,这是我到目前为止。

test.Properties.Settings.Default.list = listBox1.Items; 

你尝试过ArrayList吗?

 test.Properties.Settings.Default.list = new ArrayList(listBox1.Items); test.Properties.Settings.Default.Save(); 

然后你可以像这样加载列表:

 listBox1.Items.AddRange(test.Properties.Settings.Default.list.ToArray()); 

我还假设列表中的项目是可序列化的(实现ISerializable或具有SerializableAttribute )。

如果之后不调用Save() ,则属性的更改将不会保留。

 test.Properties.Settings.Default.list = listBox1.Items; test.Properties.Settings.Default.Save();