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. Textbox for phone number

Textbox for phone number

Scheduled Pinned Locked Moved C#
helphardwaretutorial
12 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.
  • H Offline
    H Offline
    humayunlalzad
    wrote on last edited by
    #1

    I want a textbox for a phone number. I want the text box to have this format

    ( ) -

    embedded inside it. When some one inputs the phone number the first three numbers (area code) should automatically fit in the bracket area and the next three before the hyphen and the last four after the hyphen (without the user having to type the bracket or the hyphen. I have no idea how to approach the problem. Pl help

    P 1 Reply Last reply
    0
    • H humayunlalzad

      I want a textbox for a phone number. I want the text box to have this format

      ( ) -

      embedded inside it. When some one inputs the phone number the first three numbers (area code) should automatically fit in the bracket area and the next three before the hyphen and the last four after the hyphen (without the user having to type the bracket or the hyphen. I have no idea how to approach the problem. Pl help

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Search your online help for "maskedit". There will be a ready-made one for phone numbers along with several other useful ones.

      Software rusts. Simon Stephenson, ca 1994.

      H 1 Reply Last reply
      0
      • P Peter_in_2780

        Search your online help for "maskedit". There will be a ready-made one for phone numbers along with several other useful ones.

        Software rusts. Simon Stephenson, ca 1994.

        H Offline
        H Offline
        humayunlalzad
        wrote on last edited by
        #3

        I found many which would format the phone number after it has been entered, but I could not find any where the bracket and the hyphen were already embedded in the textbox when it loads. If you can direct me to one it would be great.

        P 1 Reply Last reply
        0
        • H humayunlalzad

          I found many which would format the phone number after it has been entered, but I could not find any where the bracket and the hyphen were already embedded in the textbox when it loads. If you can direct me to one it would be great.

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          This one[^] is for dates in VB, but I am sure you can do the obvious translation. (I don't have C# or VS here, so I'm poking around in the dark a bit.) The main point is that the underlying MaskedEdit control takes care of displaying the extra bits as well as controlling what can be entered.

          Software rusts. Simon Stephenson, ca 1994.

          H 1 Reply Last reply
          0
          • P Peter_in_2780

            This one[^] is for dates in VB, but I am sure you can do the obvious translation. (I don't have C# or VS here, so I'm poking around in the dark a bit.) The main point is that the underlying MaskedEdit control takes care of displaying the extra bits as well as controlling what can be entered.

            Software rusts. Simon Stephenson, ca 1994.

            H Offline
            H Offline
            humayunlalzad
            wrote on last edited by
            #5

            The masked textbox did the trick, the only problem was that it shows those ugly looking lines

            (___)___-____

            is there a way to get rid of the lines and it just displays

            ( ) -

            but works the way the masked textbox worked. I tried providing my own mask as well, but the lines in the textbox will not go.

            V OriginalGriffO 2 Replies Last reply
            0
            • H humayunlalzad

              The masked textbox did the trick, the only problem was that it shows those ugly looking lines

              (___)___-____

              is there a way to get rid of the lines and it just displays

              ( ) -

              but works the way the masked textbox worked. I tried providing my own mask as well, but the lines in the textbox will not go.

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

              You can override the textbox class and make your own masked textbox. I don't think you can remove the lines. (maybe in the onpaint event or something?)

              V.

              P 1 Reply Last reply
              0
              • V V 0

                You can override the textbox class and make your own masked textbox. I don't think you can remove the lines. (maybe in the onpaint event or something?)

                V.

                P Offline
                P Offline
                Peter_in_2780
                wrote on last edited by
                #7

                The "lines" are underscore characters. In the corresponding Borland VCL control, you can change the character, but I don't know whether this happens in the Borland wrapper or the underlying MS control.

                Software rusts. Simon Stephenson, ca 1994.

                V 1 Reply Last reply
                0
                • P Peter_in_2780

                  The "lines" are underscore characters. In the corresponding Borland VCL control, you can change the character, but I don't know whether this happens in the Borland wrapper or the underlying MS control.

                  Software rusts. Simon Stephenson, ca 1994.

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

                  I know what "underscores" are, thank you ;P

                  V.

                  1 Reply Last reply
                  0
                  • H humayunlalzad

                    The masked textbox did the trick, the only problem was that it shows those ugly looking lines

                    (___)___-____

                    is there a way to get rid of the lines and it just displays

                    ( ) -

                    but works the way the masked textbox worked. I tried providing my own mask as well, but the lines in the textbox will not go.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    humayunlalzad wrote:

                    is there a way to get rid of the lines and it just displays

                    Simples! Just set the PromptChar property to space.

                    Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    P H 2 Replies Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      humayunlalzad wrote:

                      is there a way to get rid of the lines and it just displays

                      Simples! Just set the PromptChar property to space.

                      Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                      P Offline
                      P Offline
                      Peter_in_2780
                      wrote on last edited by
                      #10

                      Great! I was pretty sure it was in there somewhere. btw 5'd you to make up for the CCC I pinched from you a couple of weeks ago. Been meaning to do so; just found somewhere to do it! ;P

                      Software rusts. Simon Stephenson, ca 1994.

                      OriginalGriffO 1 Reply Last reply
                      0
                      • P Peter_in_2780

                        Great! I was pretty sure it was in there somewhere. btw 5'd you to make up for the CCC I pinched from you a couple of weeks ago. Been meaning to do so; just found somewhere to do it! ;P

                        Software rusts. Simon Stephenson, ca 1994.

                        OriginalGriffO Offline
                        OriginalGriffO Offline
                        OriginalGriff
                        wrote on last edited by
                        #11

                        :laugh: I don't remember it! Thanks anyway. :-D

                        Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          humayunlalzad wrote:

                          is there a way to get rid of the lines and it just displays

                          Simples! Just set the PromptChar property to space.

                          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                          H Offline
                          H Offline
                          humayunlalzad
                          wrote on last edited by
                          #12

                          Thanks a lot That was so simple, that it got overlooked

                          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