Square Root Unicode

junkie_ball

Member
Joined
Mar 25, 2010
Messages
19
Programming Experience
1-3
Hi,

I'm trying to display the square root symbol on a button in a windows form. I'm using the unicode U+221A which on windows character map is the root sign. When i enter this in visual basic ensure the font is the same as that in the character map (wasn't sure if that made a difference to the unicode) my button displays the eta sign instead. Any help greatly received.

This is the code i'm using to set my unicode the the buttons text property.

VB.NET:
btnSquareRoot.Text = CChar("U+221A")
 
Can't you just copy the char from the character map and use that ?
VB.NET:
btnSquareRoot.Text = "√"
 
Can't you just copy the char from the character map and use that ?
VB.NET:
btnSquareRoot.Text = "√"

Unfortunately not when i try to use the char √ copied from the character map the program displays an empty square box on the button in my application.
 
That sounds weird. Since you use the correct font it should display the correct char, the default Microsoft Sans Serif font supports unicode also btw. Your ".Net 3.0" profile indicates your using VB 2008 or 2010, the default file encoding here is unicode (utf-8) and support such chars also. I tested this in both environments and it worked fine in both. You could try when in code file from File menu select "Save formx.vb as..." and in the dialog click the drop-down for Save button to select "save with encoding..." (confirm 'replace it'). It should display current encoding "Unicode (Utf-8 with signature)", and if it is not select that. The encoding set for the forms plain text code file is what is used both in code, designer and at runtime, so the char may also be pasted directly into the buttons Text property in designer, that is equivalent to pasting it in the user code file.

If all else fails you can of course convert the hex string to a Char in code also:
btnSquareRoot.Text = Char.ConvertFromUtf32(Integer.Parse("221A", Globalization.NumberStyles.HexNumber))
 
That sounds weird. Since you use the correct font it should display the correct char, the default Microsoft Sans Serif font supports unicode also btw. Your ".Net 3.0" profile indicates your using VB 2008 or 2010, the default file encoding here is unicode (utf-8) and support such chars also. I tested this in both environments and it worked fine in both. You could try when in code file from File menu select "Save formx.vb as..." and in the dialog click the drop-down for Save button to select "save with encoding..." (confirm 'replace it'). It should display current encoding "Unicode (Utf-8 with signature)", and if it is not select that. The encoding set for the forms plain text code file is what is used both in code, designer and at runtime, so the char may also be pasted directly into the buttons Text property in designer, that is equivalent to pasting it in the user code file.

If all else fails you can of course convert the hex string to a Char in code also:

John,

Thanks for that info i need to update my profile as i am now using Visual Studio 2010 with the .net 4.0 framework. Either way i tried the various couple of methods you suggest. I was only your code that finally displayed the required character on my button. Thanks for the help. :D
 
Back
Top