Click here to Skip to main content
Click here to Skip to main content

Numeric TextBox : Allow your users to enter numeric data the easy way

, 20 Jun 2004
Rate this:
Please Sign up or sign in to vote.
A TextBox control for numeric input, with the ability to set precision, scale (when focused or not)


Numeric input has always been one of the key-features in many applications (CRM, Accounting,...). Although MS provides a masked edit control, many developers find it to have some limitations.

The Numeric TextBox tries to provide some features to allow the user to input numeric data in a natural way. Let's have a look at some of the key features.

  1. Allow/Disallow negative input.
  2. Specify the maximum precision and scale.
  3. Specify a different scale when the control hasn't got the focus.
  4. Allow/Disallow zero as a valid input.
  5. The control displays grouping characters.
  6. The control adapts the regional settings (grouping char, decimal char).

Using the code

To use the control simply reference the Shorty.Windows.Forms assembly in your project. Create (or drag and drop on the form) a NumericTextBox and set the properties. The properties can be set trough code or via the property pane (Numeric settings section). See below for an example.

// numericTextBox1
Shorty.Windows.Forms.NumericTextBox() numericTextBox1 = 
  new Shorty.Windows.Forms.NumericTextBox();

this.numericTextBox1.AllowNegative = true;
  new System.Windows.Forms.Binding("NumericValue", 
  this, "Table1.test"));
this.numericTextBox1.NumericPrecision = 8;
this.numericTextBox1.NumericScaleOnFocus = 5;
this.numericTextBox1.NumericScaleOnLostFocus = 3;
this.numericTextBox1.NumericValue = 0;
this.numericTextBox1.ZeroIsValid = false;

The control automatically checks if the combination NumericPrecision NumericScaleOn(Lost)Focus is valid. As you can see in the above sample to retrieve the numeric value displayed in the NumericTextBox you should use the NumericValue property. The control is also capable of databinding it's NumericValue property. (See above code sample).


  • Initial release version (20/06/2004)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Hannes Decorte
Web Developer
Belgium Belgium
3 years ago I started out with VB 6 and ASP. After seeing .Net in Beta in 2001 I haven't done anything else. I moved from VB6 over VB.Net to C#.
In 2004 I earned my MCAD. Currently I am employed as a Analyst/Developer and I'm working towards my MCDBA (1 exam to go Smile | :) ).
You can follow me at my blog

Comments and Discussions

Suggestiona complete Numerical TextBox for download PinmemberReza_m_n_6531-May-13 11:35 
QuestionI can't place it on a form... help PinmemberRolando Rocha25-Feb-13 4:56 
AnswerRe: I can't place it on a form... help PinmemberReza_m_n_6527-May-14 1:04 
GeneralMy vote of 3 PinmemberFlash2009-MX29-Nov-12 9:59 
BugI can't place it on a form... help PinmemberIApple16-Sep-11 0:29 
GeneralRe: I can't place it on a form... help PinmemberMember 82599651-Oct-11 21:34 
GeneralRe: I can't place it on a form... help PinmemberTassosK19-Oct-11 6:19 
GeneralThanx PinmemberBeni Sec10-Nov-10 8:18 
QuestionPlease help... Pinmemberdynaduo16-Sep-10 13:45 
GeneralBUG PinmemberLimitedAtonement2-Nov-09 8:11 
Generalfailed to create component Pinmembersari5sundar15-May-09 4:02 
GeneralThis methods work too Pinmembersyedmasroorahmed29-Apr-09 20:27 
GeneralFailed to create component... PinmemberJulius91125-Mar-09 5:40 
GeneralRe: Failed to create component... PinmemberJulius91127-Mar-09 7:12 
GeneralHorizontal Alignment Pinmembersalblomo4-Mar-09 9:20 
GeneralRe: Horizontal Alignment Pinmemberrgustin8-Jul-09 20:42 
GeneralGood control Pinmemberdungxpt29-Sep-08 13:48 
GeneralVery good control PinmemberBoogier26-Mar-08 1:19 
QuestionHow to Use It ? Pinmemberfreddie200023-Nov-07 6:41 
AnswerRe: How to Use It ? Pinmemberfreddie200023-Nov-07 6:50 
QuestionGreat Control, Can you modify it to add Range, Min and Max values it allows ? PinmemberVivek Krishnamurthy5-Sep-07 6:54 
GeneralDrop Control on to form PinmemberNeil Squires19-Jul-07 8:01 
AnswerRe: Drop Control on to form Pinmemberhellspawnfr1-Feb-08 23:28 
GeneralRe: Drop Control on to form PinmemberMahmood Dehghan29-Mar-08 0:08 
GeneralException Pinmembernaalexander27-Jul-06 4:12 
GeneralRe: Exception PinmemberCarlo Bos11-Jan-07 9:11 
GeneralRe: Exception Pinmemberrichm12234513234128-Apr-07 22:49 
GeneralThanks, very helpful . Pinmember-=777=-23-Jul-06 1:54 
GeneralWhat's about Cut, Copy and Paste Pinmembercarloqueirolo22-Jul-06 8:28 
GeneralRe: What's about Cut, Copy and Paste PinmemberCiupaz12-Apr-11 1:11 
Generalmy numtextbox control Pinmemberbyshome23-Mar-06 18:04 
Generalbug II Pinmemberlethedon1-Mar-06 6:15 
GeneralVery good numeric textbox - simple and efficient Pinmemberclody6-Dec-05 0:44 
GeneralRe: Very good numeric textbox - simple and efficient Pinmemberdrjoju15-Mar-06 10:20 
GeneralExcellent PinmemberKia Rahimzadeh27-Oct-04 0:02 
GeneralCursor position goes wrong when the comma appears Pinmembernvt7-Sep-04 18:43 
GeneralRe: Cursor position goes wrong when the comma appears Pinmemberasterixnz19-Sep-06 17:18 
GeneralRe: Cursor position goes wrong when the comma appears PinmemberR. van der Pal17-Dec-06 13:10 
GeneralNice! PinprotectorMarc Clifton22-Aug-04 12:40 
GeneralRe: Nice! PinmemberHannes Decorte22-Aug-04 20:01 
Questionanother one used in web ? Pinmember´ó±Ç×Ó¹·27-Jun-04 17:11 
GeneralComponent not in Toolbox PinmemberAlan Wilcox25-Jun-04 11:44 
Questionbug?? PinmemberSelvin25-Jun-04 9:18 
AnswerRe: bug?? PinmemberHannes Decorte26-Jun-04 1:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 21 Jun 2004
Article Copyright 2004 by Hannes Decorte
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid