Show Numeric keypad only for textbox containing phone number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gopishk
    New Member
    • Apr 2010
    • 15

    #1

    Show Numeric keypad only for textbox containing phone number

    I have a text box and it can contain only numbers. Similar to a phone number text box while adding a new contact. Programatically how can we open only the numeric keypad instead of both text/numeric keypad.

    By this the user cannot enter text at anytime. Though validation for symbols can be made later.
    Can you provide a code snippet for opening only a numeric keypad to enter numbers only for the text box.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    This has nothing to do with what keypad you open.
    The textbox has a .KeyPress event.
    You write a method for that event (a handler) that checks if the key just pressed was a number or not. If it was a number you allow it. If it wasn't, you throw it away.

    This is VERY common and I'm sure a Google for "C# numeric textbox" will get you a dozen examples.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      There is also a tutorial for making your own on-screen numeric keypad if you want to give it a whirl.
      This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.

      Comment

      • gopishk
        New Member
        • Apr 2010
        • 15

        #4
        The validation of entering numbers is already done as:

        Code:
        void textbox_phoneNumber_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
                {
                    //Ignore if not 0-9 or backspace char
                    if ((e.KeyChar < '0' || e.KeyChar > '9') && (e.KeyChar != '\b'))
                    {
                        e.Handled = true;
                    }
                }
        But i want only the numeric virtual keypad to be seen on screen, when focus is on this textbox..Please help me with a method for it. Iam very new to C#.

        thanks in advance,
        Gopish
        Last edited by tlhintoq; Apr 5 '10, 11:29 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          But i want only the numeric virtual keypad to be seen on screen,
          What do you be "the" onscreen numeric keypad? There isn't one that ships in Windows. Did you make one of your own? Did you get a custom control from some other source?

          Win7 has an option to turn on the number pad as part of it's fullsize keyboard


          Otherwise you can make the numeric keypad that is in my tutorial that I pointed you to and use that.

          Comment

          • gopishk
            New Member
            • Apr 2010
            • 15

            #6
            Iam working on Windows Mobile 5.0 that uses C# coding. And on Smartphones virtual keypad comes on the screen whenever there is a textbox to write into it.

            I have this textbox that validates only numbers to be entered, but i dont want the character virtual keyboard to arrive on screen, instead by default for this text box, only the numeric keypad to come always.

            can you share some small code for textbox.keyPres s for this?

            Comment

            • tlhintoq
              Recognized Expert Specialist
              • Mar 2008
              • 3532

              #7
              Ahhh.... See how much details like that help color the landscape?

              Have you tried Googling for "Windows mobile numeric keypad" and similar things?

              I found this with that Google combination:
              The home for technical questions and answers at Microsoft. Get started asking, answering, and browsing questions about products like .Net, Azure, or Teams.


              Can you access those properties for the TextBox?

              Comment

              • gopishk
                New Member
                • Apr 2010
                • 15

                #8
                Thanks for the search,
                actually iam looking for the same thing in C#.

                The properties of TextBox mentioned are not available in C#.

                Can you suggest something similar in C#?

                Comment

                • tlhintoq
                  Recognized Expert Specialist
                  • Mar 2008
                  • 3532

                  #9
                  I can suggest, to make a custom textbox that does what you need.

                  Comment

                  • gopishk
                    New Member
                    • Apr 2010
                    • 15

                    #10
                    Do you have any idea about how to implement a custom textbox?
                    Is this the only way? I thought there would be a simple way to pull a numeric keypad on the screen using C#, similar to the previous link you sent?

                    Comment

                    • tlhintoq
                      Recognized Expert Specialist
                      • Mar 2008
                      • 3532

                      #11
                      Nope. Gotta build it yourself.
                      Inheritence is a really common thing. You can either worry and fret and be afraid of it (so go to cooking school instead) - or you can take a deep breath and give it a try.


                      Just inherit from TextBox and add some rules/behaviors to match your need. It will just take a little practice and learning, like everything in life. Then you'll get the hang of it and it won't be so scary.

                      If you were expecting everything you could ever want or need to already be coded for you, so all you had to do was drag and drop from the tool box... someone lied to you.

                      Do these tutorials from start to end and I think you'll find it something well within you skills.
                      Events tutorial (including Form to Form which is the same as class to class)
                      This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.

                      Comment

                      Working...