textbox that accepts numbers only. urgent!
-
i want to make a textbox that would only accept numbers as an input... can you please give me sample codes. thanx! i am using vb.net 2002 (desktop application):-D
-
i want to make a textbox that would only accept numbers as an input... can you please give me sample codes. thanx! i am using vb.net 2002 (desktop application):-D
i already got the answer to my own question... in case somebody else will need it here's what to do: --put the following code in the Key_Press event of the textbox control. If e.KeyChar.IsNumber(e.KeyChar) = False Then e.Handled = True End If --then that's it! it would only accept numbers!
-
i already got the answer to my own question... in case somebody else will need it here's what to do: --put the following code in the Key_Press event of the textbox control. If e.KeyChar.IsNumber(e.KeyChar) = False Then e.Handled = True End If --then that's it! it would only accept numbers!
One update. e.Handled = Not (Char.IsNumber(e.KeyChar) or Char.IsControl(e.KeyChar)) I have shuffled the code a little, but either way, the core thing is that you check Char.IsControl, otherwise things like backspace will not work.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
One update. e.Handled = Not (Char.IsNumber(e.KeyChar) or Char.IsControl(e.KeyChar)) I have shuffled the code a little, but either way, the core thing is that you check Char.IsControl, otherwise things like backspace will not work.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
youre right! i didnt check that! thanx!