How do I force a user to type only two digits after the decimal point?
For example:
100 - good
100.1 - good
10.21 - good
10.123 - bad
21.1234 - bad
I need it at entry time - in C# and Windows CE.
How do I force a user to type only two digits after the decimal point?
For example:
100 - good
100.1 - good
10.21 - good
10.123 - bad
21.1234 - bad
I need it at entry time - in C# and Windows CE.
If it's a WinForms TextBox, you can trap the KeyPressed
event and test validity/squelch input then. However this won't directly prevent a user from pasting in an invalid value, so you will still need to do proper validation.
You can use a maskedtextbox and let .NET do the work for you. MSDN But I don't know if this is available on the WindowsCE platform. If not: use the KeyPressed event of a normal textbox and check the input, if the input is bad. Put the key to handled so it will be not entered in the textbox.