Feb 18th, 2003, 12:07 PM
VB - An ActiveX control which restricts a textbox to numbers
The attached control is a modified TextBox which restricts the user to numbers. The control also has these additional properties:
CanHaveDecimals - A Boolean property that determines if the number can have decimals
CanBeNegative - A Boolean property that determines if the number can be negative
MaxDecimals - Allows the maximum number of decimals to be set
MinValue - Allows the minimum value to be set
MaxValue - Allows the maximum value to be set
DecimalSeparator - Determines which character ("." or ",") is used as the decimal separator
RequireLeadingDigit (New) - Determines if at least one digit must preceed the decimal separator.
The code for the control is included in the zip file.
- Version 1.1: Updated to include most of the normal properties associated with a textbox. Also includes the bug fix provided by dee-u.
- Version 1.2: Add Click event
- Version 1.3: Add SelStart, SelLen and SelText properties
- Version 1.4: Corrected implementation of SelStart, SelLen and SelText and also added several other properties
- Version 1.5: Changed the names of the NumberBoxClick and NumberBoxKeyPress events to Click and KeyPress. Added KeyUp, KeyDown and Change events, and corrected DblClick event
- Version 1.6: 12/02/2006 Corrected KeyUp, KeyDown, and KeyPress properties by adding standard parameters
- Version 1.7: 02/07/2007 Added Enums for Alignment and BorderStyle properties. Corrected problem where numberbox behaved as if it was locked when data with decimal points was added, and added protection against pasting in invalid characters (which I thought it already had)
- Version 1.8: 02/07/2007 Added support for paste via ctrl-V and allow for an almost unlimited number of decimals
- Version 1.9: 06/11/2007 Added MinValue and MaxValue properties
- Version 1.10: 02/27/2008 Added DecimalSeparator property. Also fixed a bug which occurred when more than the allowed number of decimals was entered
- Version 1.11: 03/14/2008 Changed code so that an attempt to add a second decimal separator is ignored rather than causing the first one to be removed. Corrected bug where adding a decimal separator to a negative number would cause one too few decimal places to be shown.
- Version 1.12: 04/25/2008 Corrected MaxValue and MinValue processing when comma is the decimal separator. Changed the Appearance property values so that they display Flat and 3D like the normal textbox rather than 0 and 1
- Version 1.13: 05/02/2008
- Corrected MinValue and MaxValue processing so that the entry of a minus sign doesn't result in a type mismatch error.
- Changed MinValue and MaxValue processing so that if a change would violate either limit, the old value is restored rather than changing it to the MinValue or MaxValue.
- Corrected spelling of DecimalSeparator property.
- Added a Test project for those who might want to debug my code.
- Version 1.14: 10/20/2008
- Made .text the default property.
- Added categories to properties
- Version 1.15: 03/29/2009 Corrected problem where previously if you had a number that contained a decimal separator, and you selected the number with the intention of entering a new number that started with a decimal separator, the entry of the decimal separator was not allowed because it was assumed you were trying to add a second decimal separator.
- Version 1.16: 04/03/2009
- Added RequireLeadingDigit property. For example .15 would be changed to 0.15 if set to True.
- Removed MaxLength and PasswordChar properties
- Changed behavior where if number was greater than the MaxValue or less than the MinValue it dropped the last digit. New behavior changes the value to MaxValue or MinValue as appropriate.
KNOWN PROBLEMS: None
Last edited by MartinLiss; Apr 3rd, 2009 at 12:03 PM.
Reason: Updated project files
Click Here to Expand Forum to Full Width