积极答复者
如何保存RichtextBox中的文本

问题
答案
-
如题,如何保存RichtextBox中的文本
如果你要保存带有格式化的文本,请使用此方法:SaveFile(String, RichTextBoxStreamType)
[示例代码,在winForm上使用SaveFileDialog指定一个保存路径后保存]
public void SaveMyFile() { // Create a SaveFileDialog to request a path and file name to save to. SaveFileDialog saveFile1 = new SaveFileDialog(); // Initialize the SaveFileDialog to specify the RTF extension for the file. saveFile1.DefaultExt = "*.rtf"; saveFile1.Filter = "RTF Files|*.rtf"; // Determine if the user selected a file name from the saveFileDialog. if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFile1.FileName.Length > 0) { // Save the contents of the RichTextBox into the file. richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText); } }
PS:每次要是你的问题像这样提问就好了。另外最好建议你自己先动动脑子,尽量写一些代码(哪怕是出错的……),或者给出你的思路,这样我们方可探讨。
- 已建议为答案 梁猛 2012年8月16日 6:48
- 已标记为答案 Bob ShenModerator 2012年8月16日 8:34
全部回复
-
如果保存为RTF格式,使用richTextBox1.SaveFile方法
参照
http://msdn.microsoft.com/zh-cn/library/ch779a3b(v=vs.80).aspx
http://blog.csdn.net/zx13525079024
-
如题,如何保存RichtextBox中的文本
如果你要保存带有格式化的文本,请使用此方法:SaveFile(String, RichTextBoxStreamType)
[示例代码,在winForm上使用SaveFileDialog指定一个保存路径后保存]
public void SaveMyFile() { // Create a SaveFileDialog to request a path and file name to save to. SaveFileDialog saveFile1 = new SaveFileDialog(); // Initialize the SaveFileDialog to specify the RTF extension for the file. saveFile1.DefaultExt = "*.rtf"; saveFile1.Filter = "RTF Files|*.rtf"; // Determine if the user selected a file name from the saveFileDialog. if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFile1.FileName.Length > 0) { // Save the contents of the RichTextBox into the file. richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.RichText); } }
PS:每次要是你的问题像这样提问就好了。另外最好建议你自己先动动脑子,尽量写一些代码(哪怕是出错的……),或者给出你的思路,这样我们方可探讨。
- 已建议为答案 梁猛 2012年8月16日 6:48
- 已标记为答案 Bob ShenModerator 2012年8月16日 8:34