Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Textbox, Letters Only?

Help
Jason
2011-02-26
2013-04-08
  • Jason
    Jason
    2011-02-26

    Is there a way to make text boxes accept letters only?  I've looked through the documentation but I'm not seeing it anywhere.

     
  • andrew7
    andrew7
    2011-02-26

    The WidgetTextBox sample shows how to accept or reject characters with a function:

    // Show how to allow only 0-9, '-' and '.' in a textbox.
    textBoxs->onChar( & WidgetTest1::acceptOnlyNumeric );

    // Discard all chars except 0-9, '-' and '.'
    // out: true if char was handled; ie that the system does not need to handle it further.
    //
    bool acceptOnlyNumeric( WidgetTextBoxPtr textField, int keychar )
    {
    if ( isdigit( keychar ) ) return false; // Accept 0-9
    switch ( keychar )
    {
    case '.' :
    case '-' :
    case VK_LEFT :
    case VK_RIGHT :
    case VK_BACK :
    return false; // Let control handle character
    }
    return true; // Throw the char away.
    }

     
  • Jason
    Jason
    2011-02-26

    Thanks!  I had looked at the WidgetTextBox example and didn't see anything like this, but after your reply I realized that I have the SmartWin 1.01 Dev-CPP package installed and not 2.0.