Friday, 11 July 2014

Number on textbox with Winforms

The WinForm textbox is a useful widget. You can enter just about anything into it. It is possible to set a flag and make it into a password entry box where all input is substituted for something else (such as an asterix). However, there is a limitation - you can't use it for numbers only. Okay, you could use a number up/down widget, but then there is a problem of having the up/down arrows.

There are two ways of using a textbox for numbers only. The first is to read the contents and use RegEx, but this is a bit of a pain and you have to understand RegEx. A much simpler method is to extend the Textbox class