Click here to Skip to main content
15,917,321 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi, i didnt know how to title this question, but i hope it gets viewed by someone that would know how to do this.
So here is what i wanna do:

When form loads, in the text box should be "0.00" written (its ok this part).
But i want when a user types numbers in the textbox, if the number is greater then 999 (4 digits or more) then to add ',' (comma) automatically, for example, if he write 1000 in the textbox to be 1,000.00 if he writes 1000000 to be 1,000,000.00 etc etc. And when he press '.' (dot) to be on the part where he can enter the decimal number (where he can change those 2 zeros)

I wanna do this so i can make a text box where a price of an item can be inserted.



If my question isn't written good, tell me i ll try to be more clear.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Mar-12 15:59pm    
First, you should specify a control type you are using before customization: "TextBox" is not a type, it's a name for few different types in WPF, Silverlight, Forms, ASP.NET. Tag it and give a full type name. The answer could depend on that.
--SA

1 solution

Hi there,

Why not use the default NumericUpDown control with 2 decimal places and the ThousandsSeparator set to true. This will add in the regional separator for thousands so you won't need to worry about European dots as separators. E.g.

C#
System.Windows.Forms.NumericUpDown MyUpDown = new System.Windows.Forms.NumericUpDown();
MyUpDown.ThousandsSeparator = true;
MyUpDown.DecimalPlaces = 2;


This will create a box that (if in the UK) contains the following text for the input number 10000.55:
10,000.55
or in Europe 10.000,55

This is a far better solution than a custom text box. To put the currency symbol you want, use a label in front of the NumericUpDown control.

Hope this helps,
Ed
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900