I don't think the wheel's been invented yet (at least in the .NET framework). I'm sure there's something on CodeProject or the like, doing similar to what you are though, so it may be worth a Google.
The heavy lifting shouldn't be too incredibly bad though. There is a little bit more to it than at first glance.
The overly simplified example is you can handle OnKeyPress
, do a Float.TryParse
with the new character appended in. If true, keep the keypress; if false, cancel it (e.Handled = true
).
The hard part is what if they delete, cut, or paste a selection. The other thing is when they're just starting out (you might want to accept "-" as partial valid input)...