Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. textbox that accepts numbers only. urgent!

textbox that accepts numbers only. urgent!

Scheduled Pinned Locked Moved Visual Basic
csharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cutequencher
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • C cutequencher

      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

      C Offline
      C Offline
      cutequencher
      wrote on last edited by
      #2

      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!

      C 1 Reply Last reply
      0
      • C cutequencher

        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!

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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 )

        C 1 Reply Last reply
        0
        • C Christian Graus

          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 )

          C Offline
          C Offline
          cutequencher
          wrote on last edited by
          #4

          youre right! i didnt check that! thanx!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups