user34537
user34537

Reputation:

How do i see this special character in C#/.NET winform?

There is a special character which can be seen here http://www.fileformat.info/info/unicode/char/1f4a9/index.htm

I have the correct font for it, i can even copy/paste it in firefox. I can see the text in firefox without using an image. But when i paste it into winforms i do not. I see two boxes with ? inside of each. Its one letter. Oddly enough i can copy the text out and paste it into firefox and see it correctly. (Note i made sure to copy/paste regular text in firefox to ensure i am not repasting what i originally copied).

I'm setting the font like so textBox3.Font = new Font("symbola", 12); symbola has the font required to view that special character. In fact before i downloaded it and right click install on the ttf file firefox didnt show the character correctly. I have restarted my computer since.

How do i get winform to display the character properly?

Upvotes: 1

Views: 1339

Answers (2)

Serge Wautier
Serge Wautier

Reputation: 21878

It works for me:

private void Form1_Load(object sender, EventArgs e)
{
  button1.Font = new Font("symbola", 16); 
  button1.Text = "\U0001F4A9";
}

2 remarks:

  • The character is not in the BMP: It can't be represented using a single 16 bits word. In UTF16 parlance, it's a surrogate pair. Note the special encoding required in the source code above. Also, this representation doesn't work in WinForms designer properties. I had to assign the text in the class' code file.
  • I also couldn't assign the font in the WinForms designer properties: It complains that the font is not True Type, which it seems to be. Again, assigning the font in the code worked.

FWIW, my test was done using VS2008 and .NET 3.5 under Win7 x64

EDIT: I also tested it under VS2010 / .NET 4 and .NET 3.5: Works like a charm

Upvotes: 4

drharris
drharris

Reputation: 11214

You may try using a RichTextBox. I have had intermittent trouble using Unicode on the regular TextBox, even with all fonts installed correctly. It nearly always works when you set it from code, but there are sometimes problems with interactivity. At any rate, I never know the cause of it, but RichTextBox has typically worked in these situations.

Upvotes: 1

Related Questions