OK...the NumberBox user control is ready for BETA TESTING....
Also important NOTE: For use with Visual Studio 2005 .NET Framework v2.0.50727
So you say you need a control like the textbox that will only accept numeric input...
You want it to format it how
You want it to be able to accept math expression!
AND you want it to evaluate those math expressions....
Give it a spin and put it through the grinder and let me know what comes out!!!! ![]()
Overview
The NumberBox control is a user control with a single textbox control. At its very basic setup the NumberBox control is used to restrict the user to inputting only valid numeric entries (0-9 and the local decimal separator). By setting the properties of the NumberBox control it is possible to allow the user to input mathematical expressions evaluate them and also apply a custom format to the output.
Constructor: Public Sub New()
Initializes the textbox control, accessibility currently set to friend
Sets the NumberFormatInfo property to the current culture number format
Pass through properties: By setting any of the following control properties the properties of the textbox are changed:
- BackColor
- ForeColor
- Font
Public Methods:
- Evaluate
Will evaluate a mathmatical expression
param name="Expression">the string containing the math expression to be evaluated, if a valid statement it returns the answer else returns 0
- FocusNumberBox
Sets focus to the NumberBox control and puts the cursor at the right
Properties:
- SelectionStart Gets or sets the cursor point of the numberbox
- Text Gets or sets the text value of the numberbox - Useful for getting and setting math expressions
- CustomFormat Custom format to be applied when Format property is set to custom (ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/6f74fd32-6c6b-48ed-8241-3c2b86dea5f4.htm or http://msdn2.microsoft.com/en-us/library/0c899ak8.aspx )
-
FormatOnEnter Apply Format when Numberbox has focus and enter key is pressed
-
Format Type of formatting to be applied - NumberBox Format enumeration
None
Currency
Custom
[Decimal]
FixedPoint
General
Hex
Number
Percent
Roundtrip
Scientific
(ms- help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html /580e57eb-ac47-4ffd-bccd-3a1637c2f467.htm or http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx )
- AllowMath Allows basic math symbols to be entered in the numberbox restricts alpha characters from being entered
-
AllowFunctions Allows All Alpha Numerics to be entered in numberbox. If AllowFunctions is set to true AllowMath automatically gets set to true. With only AllowMath set to true only the digits 0-9, local decimal seperator and the math symbols are valid entries. If both are set to false only 0-9 and the decinmal seperator are valid entries.
-
EvaluateOnEnter The expression in the numberbox will be evaluated on enter when the numberbox has focus. Note: correct function syntax must be used. If the expression can not be parsed or evaluated then 0 is returned. Also variable expressions and variable substitutions are will not be evaluated. Example: Valid Input Sin(90)*(9!+3)/4 – 2^5 + ln(3) -however the following is not valid (a+1)
-
Number Gets or Sets the numeric value of the numberbox
-
NumberFormatInfo Gets or sets the number format info. Initialy set to the local culture number format
Supportted Functions:
Sine – sin(x)
Cosine- cos(x)
Tangent- tan(x)
Arcsine- arcsin(x)
Arccosine – arccos(x)
ArcTangent- arctan(x)
Sqaure Root- sqrt(x)
Maximum- max(x,y)
Minimum- min(x,y)
Floor- floor(x)
Ceiling- Ceiling(x)
Natural logarithm- Log(x)or ln(x)
Logarithm- logx(x,base)
Base 10 logarithm- log10(x)
Round – round(x)
Round – roundxy(x,y)
Absolute Value- abs(x)
Negitive- neg(x)
Positive- pos(x)
Greatest Common Factor – gcf(x,y)
Supportted Math Symbols:
(, ), *, ^, +, -, /, !, =, pi, e
http://msdn2.microsoft.com/en-us/library/system.math_members.aspx
http://codegallery.gotdotnet.com/NumberBox
Contains Setup.exe and Setup.msi...the setup files will install the NumberBox.dll assembly in the GAC and to
Program Files\Duran\Control Libraries. It will also install a test project called NumberBoxTest located: Program Files\Duran\Control Libraries\NumberBoxTest. Once installed the NumberBox user control is available for selection from the Tool box choose items menu. And the test project will be available from your programs menu.

NumberBox User Control
vtortola
Do you have just the control which doesn't install itself in the GAC
r2d2-proton
JeremyAtGosub
First....every control is a component...although visa versa is not true....
a couple of notes from:
http://msdn2.microsoft.com/en-us/library/0b1dk63b.aspx
Class vs. Component vs. Control
...
If your class is neither designable nor holds external resources, you do not need an IComponent or an IDisposable type.
...A control is a component that provides (or enables) user-interface (UI) capabilities.
Now if you are asking why I didn't make all of the textbox properties available to the developer...it is because it is targeted for beginners and ease of use
Shahid Mahmood
I've not see the code yet but I'm wondering why you create a User Ctrl instead of a component that will override only certain methods or properties
Jimmy_fingers
Hey SJ...There is a new download "Just the dll"
fdc2005