最近我一直非常喜欢C#,我只是用它测试,但似乎有一部分我没有得到.
基本上我想要它,这样当我点击SAVE按钮时必须将列表框中的所有项目保存到文本文件中.目前在文件中提出的所有内容都是System.Windows.Forms.ListBox+ObjectCollection.
这是我到目前为止所得到的.随着SaveFile.WriteLine(listBox1.Items);我尝试使用许多不同的方法的部分,我似乎无法搞清楚.还要记住,在我的程序的最终产品中,我希望它回读那个文本文件并将文本文件中的内容输出到列表框中,如果这不可能那么我的不好,我是新手C#毕竟;)
private void btn_Save_Click(object sender, EventArgs e)
{
const string sPath = "save.txt";
System.IO.StreamWriter SaveFile = new System.IO.StreamWriter(sPath);
SaveFile.WriteLine(listBox1.Items);
SaveFile.ToString();
SaveFile.Close();
MessageBox.Show("Programs saved!");
}
Run Code Online (Sandbox Code Playgroud)