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

ADO.NET
ADO.net连接数据库步骤及分析
我对ADO.NET的一点点理解
ADO.NET连接数据库
ADO.NET连接池FAQ
关于ADO.Net连接池(Connection Pool)的一些个人见解
ado.net事务的使用
ADO.NET非连接类(一)关于DataTable、DataColumn和DataRow对象的创建
最佳实践 ADO.NET实用经验无保留曝光
ado.net中的自动获取存储过程参数
ado知识遗补
ADO.Net读取Excel中的数据
Java 实现 ADO.NET DataTable
Remoting笔记:错误:“由于安全限制,无法访问类型System.RunTime.Remoting.ObjRef”
ADO.NET与抽水的故事 系列六:水池子:DataTable
趣味理解ADO.NET对象模型
浅谈ADO.NET中的五个主要对象
ADO.NET 和 ADO 的比较
ADO.NET 概述
ADO.net与PowerBuilder
ADO.NET 如何读取 Excel

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 376 ::
收藏到网摘: 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);}

}