none
如何保存RichtextBox中的文本 RRS feed

答案

  • 如题,如何保存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:每次要是你的问题像这样提问就好了。另外最好建议你自己先动动脑子,尽量写一些代码(哪怕是出错的……),或者给出你的思路,这样我们方可探讨。


    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    2012年8月15日 2:10
    版主

全部回复