views:

338

answers:

3

When I copy, for example, the word "Çamlık" from a web page into a rich text box (forms application) at runtime, it is displayed as "?aml?k". Is there a setting in the richtextbox control or form or application to fix this? If not, what is the "socially acceptable" method?

(.Net 2008)

A: 

What font is your textbox using? When I use the default font in a tiny test program, it works fine:

using System.Windows.Forms;

class Test
{
    static void Main()
    {
        RichTextBox tb = new RichTextBox();
        Form form = new Form();
        form.Controls.Add(tb);
        Application.Run(form);
    }
}

That's cutting from Chrome on Vista and pasting into the above program compiled and run from the command line.

Do you get question marks immediately after pasting? Do you have any other processing in your text box? What does the above program do for you? Which browser are you using?

Jon Skeet
I'm using a richtextbox rather than a textbox control. And I just tried it again with a different web site, and it works OK. Apparently it depends on the html character set. I'll see if I can narrow that down.
xpda
OK, I am beginning to wonder about the hallucinatory effects of Diet Coke. I found the original text on Wikipedia (http://en.wikipedia.org/wiki/TCDD_5701_Class), pasted again, and now it works fine, no question marks. It also works in a regular text box, although I didn't try that earlier. For the record, I am using Firefox 3.5.3. It occurred immediately after pasting, and there was no other processing in the rich text box. Nothing has been reset since the original occurences, not even the browser or vs. Maybe I'll put it down to browser weirdness.
xpda
Editing my example to be more appropriate. Still can't reproduce though... very odd.
Jon Skeet
A: 

I think that could be due to the fonts setting on the richtextbox which doesn't seem to have support for the character range that you are pasting.

Try setting the font to something that supports the unicode range of characters, you are pasting. Try Arial Unicode MS & see if that works.

EDIT: On a side note, does the site that you are copying text from have things in unicode?
It is possible that the site might have text in ASCII & use a specific font to render it for a specific language.

shahkalpesh
I'm not sure what the real answer is (was), but I'll select this for the "answer" because of the good suggestions.
xpda
A: 

If you have a custom paste method, be sure to paste as DataFormats.UnicodeText as opposed to DataFormats.Text; as the latter is ANSI only which would give you the '?' characters as a replacement for the Unicode chars.

TodK