0

I wanted to display greek letter lambda in a richtextbox (winforms 4.5.2).

My RTF will look as below:

richTextBox1.Rtf = "{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}}\\uc1\\pard\\f0\\fs24 pdioxaborolan-2-yl)phenyl]-λ⁶-sulfane}";

but it always display λ⁶ as two ?? (question marks)

I also tried putting \u03BB instead of the Greek symbol directly, didn't made any change in output.

Please help to display the greek letter.

If I assign the text directly then it works.

richTextBox1.Text = "pdioxaborolan-2-yl)phenyl]-λ⁶-sulfane";

(In this case lambda display as Greek letter but superscript shows as box)

Thank you...

  • Your `richTextBox1.Text = "..."` example works for me for both chars, ensure the font your using actually has superscript characters. You can always *roundtrip* - set the correct value manually (or paste) then dump `richTextBox1.Rtf` to see what the actual markup format is. – Alex K. Jul 24 '18 at 14:31
  • But I need to assign RTF to the richTextBox, not as text – user3616017 Jul 24 '18 at 14:48
  • You need to use `RICHEDIT50W`. Take a look at [this post](https://stackoverflow.com/a/47437868/3110834). You can find an example [here](https://stackoverflow.com/a/32618479/3110834). – Reza Aghaei Jul 24 '18 at 16:29

1 Answers1

0

The short answer is that the RTF you show does not support the characters, my guess is the font.

As a test I added some text to a richtextbox(RTB). The font of the RTB does not support those characters. With this code I was able to add your text correctly to the end of the RTB

    RichTextBox1.SelectionStart = RichTextBox1.TextLength - 1
    RichTextBox1.SelectionLength = 0

    RichTextBox1.SelectedRtf = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset161{\*\fname Times New Roman;}Times New Roman Greek;}}\uc1\pard\f0\fs24 pdioxaborolan-2-yl)phenyl]-\f1\'eb\f0\u8310?-sulfane}"

The results

sd              486
sdivs             1
------------
Total           531

Other           540  e.g. text, comment

pdioxaborolan-2-yl)phenyl]-λ⁶-sulfane
dbasnett
  • 11,334
  • 2
  • 25
  • 33
  • Thanks dbasnett. My actual requirement was to dynamically form the RTF and show the content because the text will get changed based on the input. Now as quick workaround what I am doing is creating a temporary richtextbox and assign the Text and then take out the RTF from the tempRichTextBox. I need to create RTF for some other save purposes. – user3616017 Jul 25 '18 at 10:03