2

我正在尝试将一些任意文本写入自定义控件。
我的代码有效,但是当我尝试绘制诸如 ü 之类的字符时,它会在字符所在的位置显示一个空方块。
我需要它来工作,因为我打算支持本地化。
我已经检查过了,Tahoma 有所需的字符。我的代码如下:

string _Label = "Zurück";
Font labelFont = new Font("Tahoma", 9, FontStyle.Bold);
SizeF labelSize = e.Graphics.MeasureString(_Label, labelFont);
this.Width = (int)(labelSize.Width + this.Padding.Horizontal);
e.Graphics.DrawString(_Label, labelFont, Brushes.White, new PointF(this.Padding.Left, this.Padding.Top));

有人知道怎么修这个东西吗?

4

2 回答 2

1

如果您使用的字体不包含字形,您将看到一个矩形。你知道事实并非如此,Tahoma 肯定有 ü。这意味着真正的问题是您没有正确地真实文件。

您需要了解文件中的文本是如何编码的。您知道它不是 UTF8,这是 StreamReader 的默认设置。你的下一个猜测可能应该是:

        var sr = new StreamReader(path, Encoding.Default);
        // Read file...
于 2010-08-18T01:59:47.773 回答
0

确保字体支持字符(使用charmap或其他东西)并使用unicode。

例如:\u00FC 应该是您要查找的字符

以 Unicode 格式读入文件:

StreamReader UnicodeFileRead new StreamReader(input, System.Text.Encoding.Unicode);
于 2010-08-17T23:15:04.187 回答