如何在我的C#代码中加载预先存在的.txt文件作为.rtf文件如果 我想将其显示在richTextBox上?我正在运行Visual Studios Windows 应用程序。如何将.txt文件上传为C#中的.rtf文件?
非常感谢。
如何在我的C#代码中加载预先存在的.txt文件作为.rtf文件如果 我想将其显示在richTextBox上?我正在运行Visual Studios Windows 应用程序。如何将.txt文件上传为C#中的.rtf文件?
非常感谢。
尝试
string text = File.ReadAllText("filename.txt");
MyRichTextBox.Rtf = text; // oops, flying blind here
您也可以尝试
MyRichTextBox.LoadFile("filename.txt", RichTextBoxStreamType.PlainText);
编辑:修正添加RichTextBoxStreamType
参数。
如果文本文件包含纯文本和RTF格式不是文本,你可以使用:
MyRichTextBox.Text = File.ReadAllText("filename.txt");
与之相对'MyRichTextBox.Rtf =文本;' – 2010-05-11 22:02:57
@joel你知道你可以有固定的我的错误并节省了我一些尴尬,但nOOOOOoooo .... – Will 2010-05-12 12:49:21