当前位置: 首页 > 图文教程 > .Net技术 > ADO.NET > ADO.NET:小编教你如何使用RichTextBox控件保存文件

ADO.NET
掌握ADO.NET的十个热门技巧
ADO.NET 的最佳实践技巧
ado详细介绍
ADO.NET 使用Tracing生成LOG
剖析 ADO.NET 批处理更新(深入研究数据访问)
ADO.NET中的多数据表操作读取
ADO与ADO.NET的区别
ADO.NET:ADO.NET访问Oracle 9i存储过程(上)
ADO.NET:ADO.NET访问Oracle 9i存储过程(下)
ADO.NET:使用 Ado.net 获取数据库架构信息
ADO.NET:浅谈LINQ to SQL集成数据库语言优劣
ADO.NET:ADO.NET实现定时音乐播放功能
ADO.NET:ADO.NET中转换数据类型
ADO.NET:在ADO.NET中实现数据库的事务处理
ADO.NET:用应用程序创建XML文档并写入内容
ADO.NET:计算字符串中子字符串出现的次数
ADO.NET:程序实现搜索文件功能
ADO.NET:编程实现移动正在使用的文件
ADO.NET:小编教你如何使用RichTextBox控件保存文件
ADO.NET:ListView控件添加搜索功能

ADO.NET 中的 ADO.NET:小编教你如何使用RichTextBox控件保存文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 377 ::
收藏到网摘: n/a

可以使用RichTextBox控件的SaveFile方法来保持RichTextBox控件中的内容。SaveFile方法有多种重载形式,本实例所用的重载形式如下:

Public void SaveFile(string path,RichTextBoxStreamType fileType)

SaveFile 方法将RichTextBox的内容保存到特定类型的文件中。Path是要文件的名称和位置;fileTypeRichTextBoxStreamType枚举值之一。

下面给出大家一些主要的代码:

Private void button1_Click(object sender,EventArgs e)

{

     openFileDialog1.Filter=”text.rtf|*.rtf”;

     if(this.openFileDialog1.ShowDialog()==DialogResult.OK)

     {

          This.richTextBox1.LoadFile(this.openFileDialog1.FileName,RichTextBoxStreamType.RichText);

 

     }

}

Private void button2_Click(object sender,EventArgse)

{

  If(richTextBox1.Text!=””)

{

   saveFileDialog1.DefaultExt=”*.txt”;

   saveFileDialog1.Filter=”Txt Files|*.txt”;

   if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)

   if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)

    {

         This.richTextBox1.SaveFile(this.saveFileDialog1.FileName,

RichTextBoxStreamType.PlainText);

MessageBox.Show(“保存成功”,”信息提示”,

MessageBoxButtons.OK,MessageBoxIcon.Information);

    }

}

Else {MessageBox.Show(“请打开文件信息提示”,

MessageBoxButtons.OK,MessageBoxIcon.Information);}

}