开发者

How to upload a .txt file as a .rtf file in C#?

开发者 https://www.devze.com 2022-12-30 11:02 出处:网络
How can I load a pre-existing .txt file as a .rtf file in my C# code if I 开发者_StackOverflowwant to display it on a richTextBox? I am running Visual Studios Windows

How can I load a pre-existing .txt file as a .rtf file in my C# code if I 开发者_StackOverflowwant to display it on a richTextBox? I am running Visual Studios Windows Application.

Thank you very much.


Try

string text = File.ReadAllText("filename.txt");
MyRichTextBox.Rtf = text; // oops, flying blind here


You might also try

MyRichTextBox.LoadFile("filename.txt", RichTextBoxStreamType.PlainText); 

edit: corrected to add RichTextBoxStreamType parameter.


If the text file contains plain text and not text in rtf format, you can use:

MyRichTextBox.Text = File.ReadAllText("filename.txt");
0

精彩评论

暂无评论...
验证码 换一张
取 消