In my recent project, we had a requirement to create a control that would accept the monetary values.
I thought this was a fairly simple requirement and thought I would get some code from the internet. But I was surprised to find that there was no free code available or may be I did not have the patience to find one.
Basically, the work of the control is done by two functions. The first function
HandleAmountFiltering is responsible for filtering all the keys pressed and allows only the numeric keys to be passed to the control. It also checks if the value in the control matches a regular expression. The second function
FormatAmtControl fires when the control leaves the TextBox and is responsible for formatting the numbers to amount type. The
Maxlength property of the control is used to fix the number of digits allowed before the decimal point.
An amount field always has two digits after the decimal point. The control ensures that there are two digits after the decimal point. This control also handles the “Over Flow” exceptions.
Hope this control would be of some use to people like me!