cody powell dot com / projects / NumericTextbox

One of the unfortunate points of the .NET Framework is that Microsoft neglected to distribute some pretty common controls for it. For example, a numeric textbox; nowhere in Visual Studio .NET will you find a textbox control that only accepts numeric values. That's bad, because there are a lot of times when you want to limit your data entry and display actions to just numeric values, such as when you're dealing with dollar amounts and percentages.

t's not too hard to half-ass something that kinda works here, but inevitably some edge case surfaces in your control (egads, someone entered two negative signs!) that causes your whole app to mess itself and go into seclusion. It is a nasty, brutal procedure to perfect the control, and for some reason, I dedicated my Sunday afternoon to it.

Ladies and gentlemen, I introduce you to my NumericTextbox (dll, code). With it, you can accept numeric user input into a textbox and display it as a formatted number, currency amount, or percentage. It filters for valid numeric data only, and allows the developer to specify decimal precision and comma formatting. Just slap it on your form, and when you want to access the value, call the appropriate Parse method for the data type you want (Float.Parse(numericTextbox.Text), Int32.Parse(numericTextbox.Text), etc.).

I've only tried it on my laptop, so if it causes your immediate office area to burst into flames, I will accept absolutely no responsibility. Feel free to mark up the code however you want. This code has been released under the GNU Public License.