views:

69

answers:

5

hello
I have my own textbox which inherits System.Windows.Forms.TextBox
I am trying to display texts like 5000000 formatted ==> 5,000,000 but the problem is that Control.Text should return 5000000 but it should display 5,000,000.

I know it is WTF, but i really need it and i couldn't Google a lot because my native language is not English(and anyone can get it from my grammar and Im sorry for that).

A: 

use Tag property that every control has

Andrey
@Andrey:unfortunately the text is not readonly, and the user should fill it.
Behrooz
I will try to do it if other people don't send better answers.
Behrooz
A: 

You can keep origianl value in the Tag property (object).

Nagg
+1  A: 

You can use the tag property, as suggested, and update in the textchange event

Charlie boy
+1 for "suggested" keyword.
Behrooz
+1  A: 

When you want to retrieve it, convert the displayed string to an integer using int.Parse and CultureInfo.CurrentCulture then convert it back to a string using ToString and CultureInfo.InvariantCulture.

Jeff Yates
I haven't tried it, is it fast?
Behrooz
Neither have I, try it, but how else would you know the two values are equivalent - there has to be some conversion somewhere.
Jeff Yates
+1  A: 

(Note: haven't got time to look up the right method names, but hopefully I'm close enough to make sense...)

Create a custom control that derives from TextBox.

Add handlers to the control for focus events (or better, override the methods for OnFocus/OnBlur). When the control loses focus, store the current text in a private variable (say, OriginalText) and update the actual text to your formatted version. When the control gets focus, reinstate the original text.

Dan Puzey
+1 for OnBlur(i didn't know about that),but i have already done other things before but the problem was "how to show it?".
Behrooz