我正在尝试将 ListBox 项目保存在文本文件中。我从属性中添加的项目:
我的代码是:
private void button1_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (FileStream S = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
using (StreamWriter st = new StreamWriter(S))
foreach (string aa in listBox1.Items)
st.WriteLine(listBox1.Items);
}
}
文本文件中的输出为:System.Windows.Forms.ListBox+ObjectCollection