0

I have tried to create the RTF text from html when try this my html content have the text(★). In my RTF text has mentioned below,

string rtf = @"{\rtf1{\fonttbl{\f0\froman Times New Roman;}{\f1\fnil Arial;}}{\colortbl;\red238\green122\blue3;}{{\pard {\f1 \sl240\slmult1 {\b\fs24\par \qc \cf1 {XhtmlCells}\par}{\b\fs20\par \qc \cf1 {★★★✩✩}\par}{{XhtmlCells use the }{\b { RichTextBoxSupportsXHTML}}{ control from GotDotNet user samples to display XHTML formatted text inside a cell.}\par}}}}}";

I have tried to load this text in RichTextBox1.Rtf which will be shown the "?" instead of "★".

Can you please suggest me how to display this star symbol in RichTextBox. Thanks in advance

MOHANRAJ G
  • 75
  • 9

3 Answers3

3

The parser will see the "Times New Roman" font at the beginning of your string and choke.

Try this one:

{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1031{\fonttbl{\f0\fnil\fcharset1 Segoe UI Symbol;}{\f1\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.17134}\viewkind4\uc1 
\pard\sa200\sl276\slmult1\f0\fs22\lang7\u9733?\f1\par
}

Seriously, it is probably a matter of font and character set.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77
1

try:

richTextBox1.Font = new Font("Arial", 14);  
richTextBox1.Text = "Special character: \u20ac";
Barr J
  • 10,636
  • 1
  • 28
  • 46
0

What .Net framework version are you targeting? I'm guessing something prior to 4.7.

What you're seeing is a limitation of the RichTextBox being based on RICHEDIT20W with versions prior to .Net 4.7. With the 4.7.x releases, the default switched to RICHEDIT50W.

Easiest solution is to just switch to a 4.7.x framework version, as long as that's an option. If you have to use an older framework for whatever reason, you can follow something like this example (code copied below for posterity) to switch to the RICHEDIT50W editor. It's been around since the days of XP so it should be available pretty much everywhere anymore.

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);

protected override CreateParams CreateParams
{
    get
    {
       CreateParams cparams = base.CreateParams; 
       if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
       {
          cparams.ClassName = "RICHEDIT50W";
       }
       return cparams;
     }
}

I have not used the above method, but what you're experiencing is a common issue. Searching for RichTextEdit, RICHEDIT20W, and/or RICHEDIT50W will get you far more than you've ever wanted to know about the internals of a rich text editor.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343