开发者

c# textbox font problem : same font looks completely different in app then in notepad

I'm trying to display ascii-art in a textbox. If I open a specific .nfo file in notepad with the font "Lucida Console", 9pt, regular, it looks like this :

http://i48.tinypic.com/24zvvnr.png

I开发者_如何学Pythonn my app I set the font of the textbox to "Lucida Console", 9 pt, regular, it looks like this :

http://i49.tinypic.com/2ihq8h0.png

What am I doing wrong ? (Or - what should I do to get it to look like in notepad ?)


Your problem can be summed up like this: ASCII is not UTF-8, and UTF-8 is not ASCII.

The StreamReader(string) constructor initializes the StreamReader to use Encoding.UTF8, which is a UTF-8 decoder that silently attempts to resolve invalid characters. A very quick glance at the Wikipedia page for .nfo files reveals that most .nfo files are generally encoded in Extended ASCII (aka Code Page 437). While the first 127 characters of ASCII map to the first 127 bit patterns of UTF-8, the encodings are not the same, and so you will get incorrect characters if you use one where the other is expected.

You probably want:

System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(437);
System.IO.StreamReader file = new System.IO.StreamReader(fileName, encoding);


You're probably reading the file with the wrong encoding.

How are you opening the file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜