Chinese Characters

F

Figmo

I'm having a problem working with foreign characters (well....foreign
to me anyway)

I have a textbox control on a form. The font is set to MS Arial
Unicode. If I use the Chinese input method I can type characters
into this box no problem. They display correctly. I can also copy
and paste Chinese characters from web sites into this text box and
they display no problem.

Here is my problem. If I put some Chinese characters in the box,
then run this line of code:

txtBox.Text = txtBox.Text + " WHY ARE YOU DIFFERENT?";

The original characters change to question marks (with my new text
appended correctly after them)

So my question is - who has the problem?

First thought was the text box. But it appears to support displaying
the Chinese characters OK when I type them in. Or if I copy and paste
them from a Chinese web site using the clipboard. So it's not a font
display problem.

So that means it must be something to do with the way strings are
stored in C#? But I've heard they are all unicode. So how could
this be a problem?

The line above does not do any obvious conversion. I should get the
exact same contents of the text box (with some extra text added to the
end)

Any help would be appreciated.
 
P

Peter Duniho

[...]
Here is my problem. If I put some Chinese characters in the box,
then run this line of code:

txtBox.Text = txtBox.Text + " WHY ARE YOU DIFFERENT?";

The original characters change to question marks (with my new text
appended correctly after them)

So my question is - who has the problem?

I'm not sure the MS Arial font has Chinese characters in it. So, my best
guess:

When you assign a string that is entirely Chinese characters, the TextBox
control substitutes a font that does include the Chinese characters. But
when you mix your text, it either doesn't bother simply because the text
is mixed, or because the font it would ordinarily substitute doesn't
include the Roman alphabet characters you're using (and so defers to the
setting for the control).

If you want to mix Chinese characters with Roman alphabet characters,
you'll either need to use a font that includes both, or use the
RichTextBox so that you can use an appropriate font for each part of the
string.

The above is just a guess. I haven't looked at any of this closely
myself, and Unicode wasn't even around the last time I had to deal with
anything remotely like this. Hopefully it's a helpful guess but if not,
well...you get what you pay for. :)

Pete
 
M

Mihai N.

I have a textbox control on a form. The font is set to MS Arial
Unicode. If I use the Chinese input method I can type characters
into this box no problem. They display correctly. I can also copy
and paste Chinese characters from web sites into this text box and
they display no problem. ....
Any help would be appreciated.

I have tried to reproduce the problem, it all works well.
Used C#, VS 2005 (no SP1), Win XP SP2.
Created a new C# application, added a TextBox, set the font to MS Arial
Unicode, added a button and in the button event run your code.
Works ok.

Question marks mean data corruption (not bad font, or anything like this).

So, we need more data:
- Is that text box a standard or a custom text box?
- What OS version?
- What .NET version
- What language
- If you add a label and do lbl.Text = txtBox.Text (before your code),
is that ok?
- does someone overrides the get/set of Text for the textbox?
- do you have the same problem with a small, dummy application like
the one I have created/described?
- anything else that you can think of
 
K

Kalpesh

Try setting the content of the textbox to unicode using classes under
System.Encoding (could be System.Text.Encoding)

Specifically this one - txtBox.Text = txtBox.Text + " WHY ARE YOU
DIFFERENT?";

HTH
Kalpesh
 
K

Kalpesh

Try setting the content of the textbox to unicode using classes under
System.Encoding (could be System.Text.Encoding)

Specifically this one - txtBox.Text = txtBox.Text + " WHY ARE YOU
DIFFERENT?";

HTH
Kalpesh
 
F

Figmo

- do you have the same problem with a small, dummy application like
  the one I have created/described?

Man, I don't know when I'm gonna learn to always just try this
first. Sure enough - a small test program did not have the
problem. So I did some digging to find what the difference was and
traced it down to a 3rd party component I had added a few months ago
to this form. It does real time spell checking as you type in a text
box and underlines mis-spelled words in red. I had forgotten all
about it.

Commenting out this component fixed my problem.

Sorry to have bothered you all with this one......[as he slinks
backward out the door with a red face and hat in hand]
 

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