In this video, I'll show you how to make a TextBox that only accepts numbers and backspace in C#.
Sorry for my poor english and my bad voice.. My primary language is french.
The code can be found here :
http://charnycoding.pastebin.com/1uMuf6mZ
In this video, I'm using Visual C# 2008 and MS visual keyboard.
If you need some C# advices or help, you can contact me at the following email :
CharnyCoding@Hotmail.com
This vid went viral on Liechtenstein
jacquesgambl36 3 weeks ago
Thanks
PurgeToDeath 4 weeks ago
@sachintha1991 I don't know i you solved it yet, but you misspelled it is KeyPressEventArgs
Mitche23 3 months ago
thank you. took me a year to get this done.
hoilungly83 3 months ago
@jorgemaiadin : if (!Char.IsDigit(input) && input != 8 && input != 46 && input != 45)
Follow the code above. ASCII Character for negative is 45 so exempt it form validation as he did for back space and I also changed to accept decimal values with period . that has ASCII code as 46.
sefaixan 3 months ago
Thank you so much. This really helped me out. Nice and simple code.
TheodenN 5 months ago
Wow sorry, i was on my iphone and read the code wrong :( works now :D
lpguitarist06 6 months ago
Thanks! But why is my backspace not working? I went over it several times and i swear i have same as u
lpguitarist06 6 months ago
Thanks........
rajunpatel21 7 months ago
hey when i try this program ..it trows an error on that e.KeyChar thing..i dont know the reason can u please help me
the error is
Error 1 'System.Windows.Forms.KeyEventArgs' does not contain a definition for 'KeyChar' and no extension method 'KeyChar' accepting a first argument of type 'System.Windows.Forms.KeyEventArgs' could be found (are you missing a using directive or an assembly reference?)
sachintha1991 7 months ago