Accented characters and MessageBox

L

Luigi

Hi all,
how can I print correctly accented letters in my MessageBox?
If I write "cafè" it appears with the tilde.

Thanks a lot.

Luigi
 
M

Martin Honnen

Luigi said:
how can I print correctly accented letters in my MessageBox?
If I write "cafè" it appears with the tilde.

Where do you get that string from? Is it a string literal in your C#
code? Or do you read it in from a file?
 
L

Luigi

Martin Honnen said:
Where do you get that string from? Is it a string literal in your C#
code? Or do you read it in from a file?

It is hard coded in my .cs file.

Luigi
 
A

Alberto Poblacion

Luigi said:
It is hard coded in my .cs file.

MessageBox accepts Unicode strings, so accents should appear correctly
if you simply pass to it the Unicode string. It works for me to just do a
MessageBox.Show("Café"), and the accented letter is shown all right in the
message on screen.
 
C

Craig Berntson

MessageBox uses the font selected by the user. If their font doesn't support
accented characters, you can't display them.
 
M

Martin Honnen

Luigi said:
It is hard coded in my .cs file.

Does such a string display properly in some other control like a text
box? Or does the problem with those characters occur with other controls
too?
 
M

Mihai N.

Hi all,
how can I print correctly accented letters in my MessageBox?
If I write "cafè" it appears with the tilde.

You should not store accented characters in sources.
It is prone to all kind of problems (as you have discovered).
Try porting things to another OS, or move them around thru
some not-so-smart source control solutions, and you will get
more troubles.

You must always know the encoding of the file.
And you should always inform the compiler about that
(but unfortunately not all compilers can do something with that info)

In this case it looks like you are saving the source file as UTF-8
(but it is hard to tell, because the encoding of your copy-paste
depends on the news client, has nothing to do with your sources)
Giving hex values would help more.

Anyway, to store accented characters in the sources you must
- have the sources in the OS system encoding
or
- have the sources saved as UTF-16
or
- use Unicode strings and escape the high-ascii values
(for instance L"caf\u00e8")

Each option has its own problems.

For the first, move the file to another OS, or even try to compile
on a foreign system, and you are in trouble. Same if you want
(let's say) Japanese strings and to compile on a US system.

For the second, very few compilers, source control systems, diff
applications, can deal with UTF-16. Quite sad for 2010, but true.

The right thing is to store the strings in sources, and move them
to resources. That's why they were invented.
 

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