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");
精彩评论