2

I'm trying to write some arbitrary text to a custom control.
My code works, but when I try to draw characters such as ü, it displays an empty square where the character would be.
I need this to work as I intend to support localizations.
I have checked already, and Tahoma has the required characters. My code is below:

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));

Anyone know how to fix this?

Origamiguy
  • 1,294
  • 2
  • 13
  • 19

2 Answers2

1

You'll see a rectangle if the font you use doesn't contain the glyph. You know that's not the case, Tahoma definitely has the ü. Which means that the real problem is that you didn't real the file correctly.

You'll need to find out how the text in the file is encoded. You know it isn't UTF8, that's the default for StreamReader. Your next guess probably ought to be:

        var sr = new StreamReader(path, Encoding.Default);
        // Read file...
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Here, have a cookie! It worked. Interestingly, the integer value of the char was 0xFF01 higher than it should have been when I didn't specify an encoding. – Origamiguy Aug 18 '10 at 15:52
0

Makesure the font supports the character (use charmap or something) and use unicode.

Ex: \u00FC should be the character you're looking for

Reading in files as Unicode:

StreamReader UnicodeFileRead new StreamReader(input, System.Text.Encoding.Unicode);
Blam
  • 2,888
  • 3
  • 25
  • 39