tags:

views:

224

answers:

3

I need some code to convert standard C# TextBox to temperature TextBox which means adding "°C" to end of the text in the textbox with another color than the default color.

+4  A: 

To get the degree symbol you can use character code 176 e.g.

Char degree = (Char)176

You can then append this to your textbox content or I would just add a label to the right of the textbox with the degree symbol if you want to control the forecolor easily.

kerchingo
I think it's easier to use `"°"`, don't you?
Groo
+4  A: 

TextBox is a plain text editor. To get different colours you would have to muck around with a rich text box. Why not put the "°C" in a label positioned to the right of the text box? That would also make your parsing and rendering code much easier.

Christian Hayter
+1, I agree, everything else is pretty much overkill.
Groo
A: 

You could probably create your own control which inherits from TextBox and then override Text property to automaticaly add °C though other color inside the same TextBox could be problem.

Why you want to have °C in TextBox ? Can't it just be label right after TextBox ? You can set static text and color to what you want.

evilek