Results 1 to 40 of 61

Thread: Numeric Text Box

Threaded View

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Numeric Text Box

    I'm sure that there are numerous examples around that claim to provide a TextBox that accepts numbers only, with varying degrees of completeness and functionality. I've been intending to do this for some time and it's finally here. This is a rather rigorous, feature-rich example so it's not for someone who just wants to handle an event and write a couple of lines of code. It's a custom control, derived from the standard TextBox control, so you would add it to your project as is and then add an instance to your form. Its features include:

    * Text property hidden and data exposed via Value (Decimal) and NullableValue (Decimal?) properties
    * Optionally makes a sound when invalid input is rejected
    * Optionally accepts a negative sign
    * Optionally accepts a decimal point
    * Optionally allows blank input
    * Optionally converts blank input to zero automatically
    * Optionally allows standard or custom numeric format string
    * Optionally allows non-default culture formatting rules
    * Allows pasting of formatted text.

    Potential improvements to be made include:

    * Minimum and maximum values
    * Display balloon tip when invalid input is rejected
    * Customised Toolbox icon

    I've attached the class itself and a solution including the class in a DLL and a test application for putting the control through its paces. I've also included a much simpler class for those with simpler needs.

    If you find any issues or can think of any improvements, please post here. Note that the code was written in VB 2008. It would need a few adjustments to work in VB 2005; mostly changing If to IIf. Enjoy!

    I'd also like to encourage anyone who uses the class to post some feedback. Did you find using the control simple and intuitive? Etc. Many thanks.
    Attached Files Attached Files
    Last edited by jmcilhinney; Jul 17th, 2010 at 10:31 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width