Question

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?

Was it helpful?

Solution

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...

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top