Reputation: 4425
How can I set a formatted string to a RichTextBox control in a way that it shows me the formatted text, not plain text.
string example:
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1046{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\colortbl ;\red255\green0\blue0;}
{\*\generator Riched20 6.3.9600}\viewkind4\uc1
\pard\sa200\sl276\slmult1\tx568\f0\fs22\lang22 This is an \cf1\ul example\cf0\ulnone\par
}
Upvotes: 0
Views: 445
Reputation: 21337
You can set the text by using the RichTextBox.Selection.Load
method with Rtf
format:
var text = @"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1046{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\colortbl ;\red255\green0\blue0;}{\*\generator Riched20 6.3.9600}\viewkind4\uc1 \pard\sa200\sl276\slmult1\tx568\f0\fs22\lang22 This is an \cf1\ul example\cf0\ulnone\par}";
using (MemoryStream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(text)))
{
rtb.Selection.Load(stream, DataFormats.Rtf);
}
Upvotes: 1