Setting a Char Value to a Symbol
Posted
Mon, Feb 22 2010 13:15
by
Deborah Kurata
This prior post demonstrated how to set char values in VB and C#. But what if you want to display a special character, like a degree symbol?
The following code displays a heart and a degree symbol.
In C#:
// Heart
TextBox1.Font = new Font("Arial Unicode MS", 12, FontStyle.Regular);
TextBox1.Text = '\u2764'.ToString();
// Degree symbol
TextBox1.Text += "45" + '\u00B0'.ToString();
In VB:
' Heart
TextBox1.Font = New Font("Arial Unicode MS", 12, FontStyle.Regular)
TextBox1.Text = ChrW(&H2764)
' Degree symbol
TextBox1.Text &= "45" & ChrW(&HB0)
' OR
TextBox1.Text &= "45" & Chr(176)
The key here is to set an appropriate font that contains the desired symbol. Then use the Unicode or ASII value to access the specific symbol.
The result is:
To view a Unicode character map, use this link.
Enjoy!