实习效果:
知识运用:
RichTextBox控件的SaveFile方法 SaveFileDialog对象的ShowDialog方法
实现代码:
private void 打开RTF文件ToolStripMenuItem_Click(object sender, EventArgs e) { openDialog.Filter = "*.rtf|*.rtf"; if (openDialog.ShowDialog() == DialogResult.OK) { richTextBox1.LoadFile( openDialog.FileName, RichTextBoxStreamType.RichText); } } private void 保存为TXT文件ToolStripMenuItem_Click(object sender, EventArgs e) { if (richTextBox1.Text != "") { saveDialog.Filter = "File Text|*.txt"; if (saveDialog.ShowDialog() == DialogResult.OK) { richTextBox1.SaveFile( saveDialog.FileName,RichTextBoxStreamType.PlainText); MessageBox.Show("保存成功","提示", MessageBoxButtons.OK,MessageBoxIcon.Information); } } else { MessageBox.Show("请打开文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }