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. C#
  4. restricting entry in a text box

restricting entry in a text box

Scheduled Pinned Locked Moved C#
question
4 Posts 4 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.
  • A Offline
    A Offline
    ameto
    wrote on last edited by
    #1

    hi friends, can i control the text to be typed in a textbox? i.e. i want only hex data (A-F, 0-9)to be typed by the user, he should not be able to type any another data. i tried to use the keydown property also, can i delete a perticular charater from the textbox? i want the user to enter the MAC address in the form 3A:26:b9:12:34 in the text box. but when i process the text in the textbox, i want to exclude the ':'. how can i do it?

    V T S 3 Replies Last reply
    0
    • A ameto

      hi friends, can i control the text to be typed in a textbox? i.e. i want only hex data (A-F, 0-9)to be typed by the user, he should not be able to type any another data. i tried to use the keydown property also, can i delete a perticular charater from the textbox? i want the user to enter the MAC address in the form 3A:26:b9:12:34 in the text box. but when i process the text in the textbox, i want to exclude the ':'. how can i do it?

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      1. There should be an event when the textbox-contents changes. -> get the string out of the textbox, check for illegal characters, delete them, put text back into the textbox. 2. Like 1., you can get and set the text from the textbox with the "Text" property. look on msdn for more info on the textbox members and properties. good luck. No hurries, no worries.

      1 Reply Last reply
      0
      • A ameto

        hi friends, can i control the text to be typed in a textbox? i.e. i want only hex data (A-F, 0-9)to be typed by the user, he should not be able to type any another data. i tried to use the keydown property also, can i delete a perticular charater from the textbox? i want the user to enter the MAC address in the form 3A:26:b9:12:34 in the text box. but when i process the text in the textbox, i want to exclude the ':'. how can i do it?

        T Offline
        T Offline
        the last free name
        wrote on last edited by
        #3
        1. Use the KeyPress event, if the character is invalid set the e.Handled property to false, and then it won't appear in the textbox. 2) Use macAddr = textbox1.Text.ToString().Replace(":", "") Note this is from the top of my head and the syntax may be slightly off:) Hope this helps
        1 Reply Last reply
        0
        • A ameto

          hi friends, can i control the text to be typed in a textbox? i.e. i want only hex data (A-F, 0-9)to be typed by the user, he should not be able to type any another data. i tried to use the keydown property also, can i delete a perticular charater from the textbox? i want the user to enter the MAC address in the form 3A:26:b9:12:34 in the text box. but when i process the text in the textbox, i want to exclude the ':'. how can i do it?

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          Have a look at this article http://www.codeproject.com/useritems/shellcontrol.asp[^]. It demonstrates a few techniques to filter keystrokes. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          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