[求助]c#如何将listbox里的内容保存到文本里
在c#里点击按扭将listbox里的内容保存到文本里
private void button2_Click(object sender, System.EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
}
按扭的事件该怎么写,请高手指点一下
private void button2_Click(object sender, System.EventArgs e)
{
saveFileDialog1.ShowDialog();
}
private void saveFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
string names=saveFileDialog1.FileName;
StreamWriter writer = new StreamWriter(names);
int i = listBox1.Items.Count;
for(int j=0;j<i;j++)
{
writer.WriteLine(listBox1.Items[j].ToString());
}
writer.Close();
}