none
"Number"Box

    Question

  • Hi, I'm trying to make a textbox that only allows people to enter numbers - when you press a number it immediately shows the actual number, not the letter associated with it. Can anyone give a code snippet or some ideas on how to do that.
    Tuesday, February 20, 2007 8:51 PM

Answers

  • Hi,

     

    From your description I think you are attempting to develop an application for a smartphone. The problem you are finding is that pressing the '2' key on the phone is cycling through the letters A, B, and C before getting to the number 2, which is anoying when you want a textbox to only accept numbers.

     

    If this is the situation you are finding yourself in the situation is relativly easy to resolve. You don't mention if you are developing your application in managed or native code so I'll explain the solution for both situations.

     

    In managed code:

       See http://msdn2.microsoft.com/en-us/library/microsoft.windowsce.forms.inputmodeeditor.setinputmode(VS.80).aspx

     

       Include a reference to the Microsoft.WindowsCE.Forms.dll assembly

       call the method InputModeEditor.SetInputMode as follows (where textBox1 is the name of the textbox which should only accept numeric input)

     

             InputModeEditor.SetInputMode(textBox1, InputMode.Numeric);

     

    In native code:

       See http://msdn2.microsoft.com/en-us/library/ms853564.aspx

     

       Send your edit control an EM_SETINPUTMODE message as follows (where m_hwndEdit is the hwnd of your edit control)

     

            SendMessage(m_hwndEdit, EM_SETINPUTMODE, 0, EIM_NUMBERS);

     

    Hope this helps,

    Christopher Fairbairn

    Thursday, April 19, 2007 12:45 PM

All replies

  • Just use MFC EditBox and set it to numerical mode.
    Wednesday, February 21, 2007 4:44 AM
  • Where can I find that?
    Wednesday, February 21, 2007 5:34 AM
  • Edit box is available as a component within the existent MFC support that came with WM5.0 SDK.

    For more info, check:

    http://msdn2.microsoft.com/en-us/library/f7yhsd2b(VS.80).aspx

    Thursday, February 22, 2007 2:40 AM
  • Hi,

     

    From your description I think you are attempting to develop an application for a smartphone. The problem you are finding is that pressing the '2' key on the phone is cycling through the letters A, B, and C before getting to the number 2, which is anoying when you want a textbox to only accept numbers.

     

    If this is the situation you are finding yourself in the situation is relativly easy to resolve. You don't mention if you are developing your application in managed or native code so I'll explain the solution for both situations.

     

    In managed code:

       See http://msdn2.microsoft.com/en-us/library/microsoft.windowsce.forms.inputmodeeditor.setinputmode(VS.80).aspx

     

       Include a reference to the Microsoft.WindowsCE.Forms.dll assembly

       call the method InputModeEditor.SetInputMode as follows (where textBox1 is the name of the textbox which should only accept numeric input)

     

             InputModeEditor.SetInputMode(textBox1, InputMode.Numeric);

     

    In native code:

       See http://msdn2.microsoft.com/en-us/library/ms853564.aspx

     

       Send your edit control an EM_SETINPUTMODE message as follows (where m_hwndEdit is the hwnd of your edit control)

     

            SendMessage(m_hwndEdit, EM_SETINPUTMODE, 0, EIM_NUMBERS);

     

    Hope this helps,

    Christopher Fairbairn

    Thursday, April 19, 2007 12:45 PM