Let’s say I have a text box, and I have to put a number in that text box. I want it so that the number always has commas every 3 digits even when the user is adjusting the value.
On the OnChangeValue event, I read the value, convert it to double, then write it out again with commas every 3 digits, but then, because I’m rewriting the string, my cursor is back to the beginning of the string.
So now I’m thinking that I can read how many digits into the number the cursor is at before the change, and restore the location afterwards. But this seems like a lot of clutter for such a simple thing to do. Is there a more efficient way?
You can do this with the framework’s
MaskedTextBoxcontrol.See: http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx