Displaying a unicode text in C#

空扰寡人 提交于 2019-12-06 04:03:32

问题


My App displays English, Japanese and Chinese characters on a TextBox and a LinkLabel. Currently, I check if there are unicode characters and change the font to MS Mincho or else leave it in Tahoma.

Now MS Mincho displays Japanese properly, but for Chinese I have to use Sim Sun. How can I distinguish between the two?

How can I ensure that unicode text are displayed properly regardless of the font/language?


回答1:


If you have unicode characters for each of the text, using a font that supports unicode should cover it properly for you (e.g. Arial Unicode MS).




回答2:


You can't ensure that unicode text is displayed properly regardless of the font and language, because there is no single font that can render all possible unicode characters. You have to select a font that can display the unicode characters that you need to render.




回答3:


All strings in C# are Unicode. The English (Latin), Japanese and Chinese code points are just located in different code point ranges.

I think you have two options:

  • Find a Unicode font that contains characters for all code points in all three language.

  • Try to guess the language and choose a font that contains the characters for the code points in that language.

For option 2 you can look at the Unicode charts to find out where the different code points are and expand your algorithm to guess the language.

Example for Hiragana:

bool IsHiragana(char ch)
{
    return (ch >= '\u3040') && (ch <= '\u309f');
}

bool IsHiragana(string s)
{
    return s.Count(IsHiragana) > 0;
}


来源:https://stackoverflow.com/questions/1371077/displaying-a-unicode-text-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!