如何以正确的字体呈现 unicode 字符? (C#/WinForms)
我的应用程序可以正确处理不同类型的字符集,但仅限于内部 - 当涉及到在标准 WinForms 标签和文本框中显示文本时,中文字符似乎存在问题。
问题似乎是使用的字体(Tahoma),因为当我复制并粘贴文本或在调试器中查看它时,它显示正确。 另外,当我将 MS Mincho 设置为要使用的字体时,屏幕上的字符看起来不错。
当然,我不想在整个应用程序中使用 MS Mincho。 我是否必须根据显示的字符切换字体,或者是否有我错过的更好的方法?
My application correctly handles different kind of character sets, but only internally - when it comes to displaying text in standard WinForms labels und textboxes, it seems to have problems with chinese characters.
The problem seems to be the font used (Tahoma), because when I copy&paste the text, or view it in the debugger, it is displayed correctly. Also when I set MS Mincho as the font to be used, the characters on the screen look OK.
Of course, I don't want to use MS Mincho in the entire application. Do I have to switch the font depending on the characters displayed, or is there a better way I have missed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有字体都没有可以用 unicode 表示的所有字形的数据。 您必须找到具有您想要的子集的合适字体。
编辑:澄清一下,有一些字体涵盖了整个 unicode 范围,但您现在使用的字体不是其中之一。
All fonts don't have data for all the glyphs that can be expressed in unicode. You´ll have to locate a suitable font which has the subset you want.
edit: Just to clarify, there are fonts which cover the full unicode range, but the one you´re using now isn´t one of them.
UniScribe 是在 Windows 2000 中引入的,应该透明地处理这个问题,这意味着它将对于您选择的字体中不存在的字符,自动使用不同的字体(例如 Mincho)。 这就是为什么它在调试器中看起来是正确的,即使调试器中使用的字体不包含中文字符。 也许您正在做的事情会禁用 UniScribe,或者在其他方面存在问题。 也许如果您可以粘贴一些代码,可能会更容易识别问题。
UniScribe, which was introduced in Windows 2000, is supposed to handle this transparently, meaning that it will automatically use a different font (such as Mincho) for characters that aren't present in the font you've selected. This is why it looks correct in the debugger, even though the font used in the debugger doesn't contain Chinese characters. Perhaps you are doing something that disables UniScribe, or is problematic in some other way. Perhaps if you could paste some code it would be easier to identify the problem.