0

I am trying to print the Euro Symbol in my Windows forms application with the following code. It works for all other characters & symbols, but Euro(€) is not displaying.

string input = ((char)128).ToString();
Font f = new System.Drawing.Font("Arial", 12f);
Graphics gr = this.CreateGraphics();
gr.DrawString(input, f, Brushes.Black, new PointF(0, 0));

128 - is the decimal of Euro sign Can anyone help on this?

Uthistran Selvaraj
  • 1,371
  • 1
  • 12
  • 31

2 Answers2

7

128 isn't the correct value to represent the Euro sign. Maybe try:

string input = ((char)0x20AC).ToString();

Because U+20AC is the Unicode code-point for a Euro sign.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • Thanks friend, but I need the explanation that if I put 130 there, I get that particular symbol and Why no 128? – Uthistran Selvaraj Dec 10 '12 at 12:09
  • @kovilpattiCsharper - from the page you linked to, for 128-255: "There are several different variations of the 8-bit ASCII table. The table below is according to ISO 8859-1, also called ISO Latin-1. Codes 129-159 contain the Microsoft® Windows Latin-1 extended characters." So, there are several different possibilities for the ASCII values. And they don't match unicode, which is what you ought to be using if you want to supply numeric values in .NET. – Damien_The_Unbeliever Dec 10 '12 at 12:11
  • Happy with your response. Thanks, – Uthistran Selvaraj Dec 10 '12 at 12:15
1

By using the below code, I achieved printing Euro symbol without using unicode of it.

String input = Encoding.Default.GetString(new byte[] { 128 });
Font f = new System.Drawing.Font("Arial", 12f);
Graphics gr = this.CreateGraphics();
gr.DrawString(input, f, Brushes.Black, new PointF(0, 0));

This may help someone.

Uthistran Selvaraj
  • 1,371
  • 1
  • 12
  • 31