Showing unicode in a MessageBox

  • Thread starter Thread starter Tim Anderson
  • Start date Start date
T

Tim Anderson

I have VS 2003 installed on one machine, and the newly downloaded VS 2005
release on another. Both XP Pro.

I have code like this:

string s = "Extended characters: <spade> spades";
MessageBox.Show(s);

where <spade> is the symbol for a spade suit in cards. You can enter this
into the VS editor with character map.

If I run this code in VS 2003, I get the spade symbol showing in the message
box.

If I run this code in VS 2005, I get the square box for an undisplayable
character.

Is this a difference between .NET 1.1 and .NET 2.0? Or could be it be a
difference in the way Windows is set up on the two boxes?

I assume I can fix it with PInvoke to MessageBoxW, but it seems curious.

Tim
 
Is this a difference between .NET 1.1 and .NET 2.0? Or could be it be a
difference in the way Windows is set up on the two boxes?

Seems to be a font issue. Both are set to use Tahoma 8 for MessageBox, but
it appears that on one of the boxes this doesn't support the extended
character, and on the other it does.

Not sure how you get the fuller version of Tahoma, maybe by installing
Office or something.

Tim
 
Tim Anderson said:
I have VS 2003 installed on one machine, and the newly downloaded VS 2005
release on another. Both XP Pro.

I have code like this:

string s = "Extended characters: <spade> spades";
MessageBox.Show(s);

where <spade> is the symbol for a spade suit in cards. You can enter this
into the VS editor with character map.

It's a bad idea to do so, however. Use the escape format "\uxxxx"
(where xxxx is the Unicode number for the character in hex) instead.
Putting non-ASCII characters into source code is just asking for
trouble, IMO.
If I run this code in VS 2003, I get the spade symbol showing in the message
box.

If I run this code in VS 2005, I get the square box for an undisplayable
character.

Is this a difference between .NET 1.1 and .NET 2.0? Or could be it be a
difference in the way Windows is set up on the two boxes?

It could be either - you might want to check that both machines are
using the same font for the message boxes, for instance.
 
It's a bad idea to do so, however. Use the escape format "\uxxxx"
(where xxxx is the Unicode number for the character in hex) instead.
Putting non-ASCII characters into source code is just asking for
trouble, IMO.

I agree, however it is a quick way to test the problem.

Tim
 
Tim Anderson said:
I agree, however it is a quick way to test the problem.

Perhaps - it makes it a lot harder for people to test on the newsgroups
though, of course. (Posting a non-ASCII character, which you didn't do,
is somewhat unreliable.)

(There's also the issue of things which are for "quick test" purposes
making their way into production code. Maybe you're more disciplined
than I am on that front though :)
 
Back
Top