码迷,mamicode.com
首页 > 其他好文 > 详细

使用RichTextBox控件保存文件

时间:2018-12-21 22:42:29      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:else   event   end   知识   对象   分享图片   stream   src   使用   

实习效果:

  技术分享图片

知识运用:

  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); 
            }
        }

 

使用RichTextBox控件保存文件

标签:else   event   end   知识   对象   分享图片   stream   src   使用   

原文地址:https://www.cnblogs.com/feiyucha/p/10158818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!