RichTextBox bug?

R

Roger Norris

We have a font that uses unicode character 0xF000.

If I have a RichTextBox control, putting the character
0xF000 into the text box causes the font to switch to
Wingdings!

Try this:


RichTextBox myTextBox = new RichTextBox();
..
..
..
myTextBox.Text = "\uF000";


After the attempted insertion of character 0xF000, when I
try typing ordinary letters I get random garbage from the
Wingdings font, regardless of what font the RichTextBox was
previously using.

Am I doing something that I'm not supposed to? Is there is
a workaround for this problem? I really do need to use
that character.
 
H

Herfried K. Wagner [MVP]

* "Roger Norris said:
We have a font that uses unicode character 0xF000.

If I have a RichTextBox control, putting the character
0xF000 into the text box causes the font to switch to
Wingdings!

I don't know why the font is being changed, but I am able to repro that
on my Windows XP Professional machine running .NET 1.1.

"Workaround":

\\\
myTextBox.Text = "\uF000";
myTextBox.SelectAll();
myTextBox.SelectionFont = this.Font;
///
 
J

James Hancock

The reason why that's happening is that \uF000 is a byte order mark for
Unicode so that richtext box goes and sees it as something it isn't....

The windows version of the control does the same.

James Hancock
 
R

Rhett Gong

Hi Roger,
All of the characters in the Unicode range 0xF000 - 0xF0FF (inclusive)
will be used to enumerate the symbol character set. All glyphs in this
range are mapped to the range 0x0000 - 0x00FF. I think that's why you get a
symbol font instead of normal font.
For the workaround, you can take the answer from Herfried.

Have a nice day!

Rhett Gong [MS]
Microsoft Online Partner Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.
 
G

Guest

Thank you for your help, everyone.

The proposed workaround - selecting the text and changing
the font - turned out to be a little tricky to implement.
The issue was actually discovered when someone tried to
paste some text that they had copied from the Character Map.

There's not an OnPaste event that I could find (to notify
me that I may need to change the font), and I really didn't
want to use that workaround every time I got a TextChanged
event.

We went with a different solution which seems to be working
well so far. All of the:

richtextbox.Text = some_unicode_string;

....calls were replaced with:

richtextbox.Rtf = ConvertUnicodeToRTF( some_unicode_string );

....where ConvertUnicodeToRTF does exactly what it sounds like.

Also, whenever the user does a Paste, we snatch the
UnicodeText data off the clipboard, convert to RTF, and
then paste the RTF instead. (We don't want to paste the
RTF that's already on the clipboard, because we're not
interested in extras like fonts/pictures/etc...).

- Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top