locked
Handle format of input enter textbox RRS feed

  • Question

  • Hi,

    Programming in visual C++ 6.0, I have an input text box, and it is supposed to enter 3 digit number.  If I enter 2 digit number, then after I press the enter key, it will automatically change format to 3 digit number by adding a leading zero infront of the input in the textbox.  What event handler that I need to add for this textbox to handle this case.  I am not pretty much familiar with visual C++ programming.  Can anyone show me way to code to solve this task?

    Thanks in advance!

    tt.

    Tuesday, January 8, 2013 4:46 PM

Answers

  • Trap enter key and check for no of digit inside your text box if less then 3 then add corresponding zero .that's all you have to do . You also can do it by subclassing on your control.

    Thanks


    Rupesh Shukla

    • Proposed as answer by Elegentin Xie Thursday, January 10, 2013 5:55 AM
    • Marked as answer by Elegentin Xie Tuesday, January 15, 2013 9:19 AM
    Tuesday, January 8, 2013 8:34 PM
  • thanks for your sugesstion.  I trap the enter key (use event handler kill focus of that textbox) and check for length of the input in the textbox, add zero if the length is 2 and update textbox...

    I get it now.

    tt.

    • Proposed as answer by Elegentin Xie Thursday, January 10, 2013 5:54 AM
    • Marked as answer by Elegentin Xie Tuesday, January 15, 2013 9:19 AM
    Wednesday, January 9, 2013 4:13 PM

All replies

  • >Programming in visual C++ 6.0, I have an input text box, and it is supposed to enter 3 digit number.  If I enter 2 digit number, then after I press the enter key, it will automatically change format to 3 digit number by adding a leading zero infront of the input in the textbox.

    What's it do if you enter a 1-digit number and press Enter?

    Don't forget that if your text control is on a dialog, then the Enter
    key is normally the dialog's OK button default, in which case the
    dialog will disappear and you'll not see the text control anyway.

    Do you really have to have this behaviour, or is this an exercise
    you're trying out? If it's the latter, I'd recommend that you abandon
    the idea since your control will behave contrary to normal user
    expectations.

    Dave

    Tuesday, January 8, 2013 4:57 PM
  • Well, it is not an exercise.  I am trying to correct an old existing program.

    thanks for your reply.

    Tuesday, January 8, 2013 8:28 PM
  • Trap enter key and check for no of digit inside your text box if less then 3 then add corresponding zero .that's all you have to do . You also can do it by subclassing on your control.

    Thanks


    Rupesh Shukla

    • Proposed as answer by Elegentin Xie Thursday, January 10, 2013 5:55 AM
    • Marked as answer by Elegentin Xie Tuesday, January 15, 2013 9:19 AM
    Tuesday, January 8, 2013 8:34 PM
  • trap WM_CHAR event.

    Christophe Pichaud

    Wednesday, January 9, 2013 1:30 PM
  • thanks for your sugesstion.  I trap the enter key (use event handler kill focus of that textbox) and check for length of the input in the textbox, add zero if the length is 2 and update textbox...

    I get it now.

    tt.

    • Proposed as answer by Elegentin Xie Thursday, January 10, 2013 5:54 AM
    • Marked as answer by Elegentin Xie Tuesday, January 15, 2013 9:19 AM
    Wednesday, January 9, 2013 4:13 PM