dlras2
dlras2

Reputation: 8486

Can I make a rich text box display control pictures?

I'm trying to display control pictures in a rich text box. I need the textbox to remain monospaced.

When I copy-paste said characters into Visual Studio, they appear monospaced and just fine. But when being displayed in the rich text box, they're just squares. Both my IDE and text box are using Consolas.

I see this in my IDE (the last two characters are equivalent):

richtextbox.Text = new string(new[] {'→', '␣', '␂', '\u2402'});

But my text box display the first two characters, then two boxes:

→␣␂␂

How can I get the full character picture to display?

Upvotes: 0

Views: 287

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201568

With the given requirements, it seems that the only font you can use is Everson Mono. For example, the character U+2402 is contained in a handful of fonts only, according to font coverage information at Fileformat.info, and Everson Mono (together with Everson Mono Oblique) seems to be the only monospace font among them.

Using a mixture of fonts, e.g. Consolas for all characters that it covers and some other monospace font(s), will generally not work: it will break the monospace property of text. (Different monospace fonts in the same font size need not have equal advance width, and they mostly don’t.)

Upvotes: 1

Mark Ransom
Mark Ransom

Reputation: 308158

There are very few fonts in Windows that contain a large number of oddball characters from the Unicode character set. When I paste one of your control characters into Word, it converts it to the Arial Unicode MS font which appears to be the backup for characters that aren't available in a font.

Try setting the font in the Rich Edit to Arial Unicode MS before you insert the character.

Upvotes: 1

Related Questions