我可以使用「StreamWriter」功能將文本保存到ListBox中嗎?如何保存ListBox中的文本?
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.DefaultExt = "*.txt";
saveFile1.Filter = "Text files|*.txt";
if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
saveFile1.FileName.Length > 0)
{
using (StreamWriter sw = new StreamWriter(saveFile1.FileName, true))
{
sw.WriteLine(listBox1.Text);
sw.Close();
}
這是列表框中的所有項? –