2
votes

If you paste the below into a RichTextBox, the CJK character and everything afterwards turns into a second font - SimSun.

Inserting a CJK character: 色

...makes this font change.

This affects the formatting of the RichTextBox in an unwanted way, and also massively slows down large copy/pastes.

I have tried setting the RichTextBox to use a unicode font such as "Lucida Sans Unicode", and also made sure the source I was copying from (Wordpad) was also using the "Lucida Sans Unicode" font. However, at the end of the day, when I paste to the RichTextBox, it forces the use of another font such as SimSun (or other fonts like "Shonar Bangla" or "Microsoft Himalaya" if we use another type of character).

Since "Lucida Sans Unicode" has them all, why can't it stick to the one font?

I noticed someone else also has a similar problem: RichTextBox - retain original formatting (font), even after paste

Unfortunately, the solutions on that page didn't work for me as I still find the RTB uses another font after the CJK character.

3

3 Answers

7
votes

I've been having this problem on and off, myself.

After flipping around here and there on the internet today, I noticed something on msdn and tried something. Add this line to your Form1_Load(), or to the form constructor AFTER the InitializeComponent() line:

richTextBox1.LanguageOption = RichTextBoxLanguageOptions.DualFont;

I'm no expert, and I can't tell you anything about WHY it works but it DOES for me!

2
votes

Unfortunately despite its slightly confusing name, Lucida Sans Unicode doesn't contain CJK characters (as you could expect from fonts with Unicode in its name). This triggers some font fallback mechanism which results in a font that contains the required symbol. The only possible solution I see is to use a font that actually contains all required characters.

0
votes

To complement Petr's answer (and partially use information from his comment), it turns out that many Unicode symbols render much slower in a RichTextBox.

But by filtering out unicode characters from about 1280 (0x500) and greater, I have found the paste to be as quick as before.