How to display Rich Text RTF Content using ComponentOne WinForms Controls
Many of our customers have asked quite a few times if there is any control that can be used to load and preview rich text files text files (.rtf). There is no ComponentOne control that supports this feature directly in WinForms (our WPF RichTextBox does display RTF content). However, we do have a workaround to achieve this using C1PrintDocument. In order to preview the .rtf file, one must follow the undermentioned steps:
1. Create an instance of StreamReader
2. Read the whole text of the .rtf file using this stream reader
3. Create an instance of C1PrintDocument
4. Write this text to this C1PrintDocument using the RenderRichText object (use RenderText object for .txt files)
5. Add the RenderRichText to the C1PrintDocument.
6. Now you can preview this C1PrintDocument in C1PrintPreviewControl.
sr = New StreamReader("RichTextFile.rtf")
str = sr.ReadToEnd
Dim rendertext As New RenderRichText
rendertext.Rtf = str
C1PrintDocument1.Body.Children.Add(rendertext)
C1PrintDocument1.Generate()
C1PrintPreviewControl1.Document = C1PrintDocument1