zoukankan      html  css  js  c++  java
  • 【C#】利用富文本框打开,保存text文件【源代码】

    private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)

            {

                OpenFileDialog open = new OpenFileDialog();

                open.InitialDirectory = "F:\\";     //设置初始目录

                open.Filter = "文本文件(*.txt)|*.*|(*.htm)|*.htm"; //打开htm类型文件或text文件

                open.RestoreDirectory = true;   //设置对话框在关闭前还原当前目录

                open.FilterIndex = 1;

                if (open.ShowDialog() == DialogResult.OK)

                {

                    string str = open.FileName;

                    StreamReader sr = File.OpenText(str);

                    string s;

                    while ((s = sr.ReadLine()) != null)

                        this.richTextBox1.Text += s;

                    sr.Close();

                }

            }

     

            private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)

            {

                SaveFileDialog save = new SaveFileDialog();

                save.InitialDirectory = "C:\\";

                save.Filter = "(*.txt)|*.*|(*.cs)|*.cs";    //打开cs文件或text文件

                save.RestoreDirectory = true;

                save.FilterIndex = 1;

                if (save.ShowDialog() == DialogResult.OK)

                {

                    string str = save.FileName;

                    //向指定的文件中追加内容,如果文件不存在,则创建文件

                    StreamWriter sw = File.AppendText(str);

                    sw.Write(this.richTextBox1.Text);

                    sw.Flush();

                    sw.Close();

                }

            }

     

  • 相关阅读:
    jquery+easy ui 实现表格列头筛选
    javascript 未结束的字符串常量
    C# 中带@字符串中的转义符号
    .net 和java JSON 模板
    百度下载google 浏览器安装失败
    无法在web服务器上启动调试,此项目在使用一个被配置为使用特定IP地址的网站。请在项目URL中指定计算机名称。
    无法在web服务器上启动调试,服务器不支持对ASP.NET 或ATL Server应用程序进行调试。
    CSS Select 标签取选中文本值
    CSS 文章段落样式
    第二个冲刺周期第一天
  • 原文地址:https://www.cnblogs.com/ngnetboy/p/2390136.html
Copyright © 2011-2022 走看看