winform c# richtextbox保存为txt文本文档

winform c# richtextbox保存为txt文本文档


private void btn_Save_Click(object sender, EventArgs e)
{
if (this.richTextBox1.Text == "")
return;
saveFileDialog1.DefaultExt = "txt";
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
if (this.saveFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string FileName = this.saveFileDialog1.FileName;

if (saveFileDialog1.ShowDialog() == DialogResult.OK &&FileName.Length > 0)
{
// Save the contents of the RichTextBox into the file.
richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
MessageBox.Show("文件已成功保存");
}
}

你可能感兴趣的:(C#2005)