Click here to Skip to main content
13,145,417 members (85,583 online)
Click here to Skip to main content
Add your own
alternative version

Stats

326.8K views
4.8K downloads
56 bookmarked
Posted 20 Jun 2004

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)

Introduction

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;
this.numericTextBox1.DataBindings.Add(
  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).

History

  • Initial release version 0.1.0.0 (20/06/2004)

License

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

Share

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 http://radio.weblogs.com/0132279/

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Suggestiona complete Numerical TextBox for download Pin
Reza_m_n_6531-May-13 10:35
memberReza_m_n_6531-May-13 10:35 
QuestionI can't place it on a form... help Pin
Rolando Rocha25-Feb-13 3:56
memberRolando Rocha25-Feb-13 3:56 
AnswerRe: I can't place it on a form... help Pin
Reza_m_n_6527-May-14 0:04
memberReza_m_n_6527-May-14 0:04 
GeneralMy vote of 3 Pin
Flash2009-MX29-Nov-12 8:59
memberFlash2009-MX29-Nov-12 8:59 
BugI can't place it on a form... help Pin
IApple15-Sep-11 23:29
memberIApple15-Sep-11 23:29 
GeneralRe: I can't place it on a form... help Pin
Member 82599651-Oct-11 20:34
memberMember 82599651-Oct-11 20:34 
GeneralRe: I can't place it on a form... help Pin
TassosK19-Oct-11 5:19
memberTassosK19-Oct-11 5:19 
GeneralThanx Pin
Beni Sec10-Nov-10 7:18
memberBeni Sec10-Nov-10 7:18 
QuestionPlease help... Pin
dynaduo16-Sep-10 12:45
memberdynaduo16-Sep-10 12:45 
GeneralBUG Pin
LimitedAtonement2-Nov-09 7:11
memberLimitedAtonement2-Nov-09 7:11 
Generalfailed to create component Pin
sari5sundar15-May-09 3:02
membersari5sundar15-May-09 3:02 
GeneralThis methods work too Pin
syedmasroorahmed29-Apr-09 19:27
membersyedmasroorahmed29-Apr-09 19:27 
GeneralFailed to create component... Pin
Julius91125-Mar-09 4:40
memberJulius91125-Mar-09 4:40 
GeneralRe: Failed to create component... Pin
Julius91127-Mar-09 6:12
memberJulius91127-Mar-09 6:12 
GeneralHorizontal Alignment Pin
salblomo4-Mar-09 8:20
membersalblomo4-Mar-09 8:20 
GeneralRe: Horizontal Alignment Pin
rgustin8-Jul-09 19:42
memberrgustin8-Jul-09 19:42 
GeneralGood control Pin
dungxpt29-Sep-08 12:48
memberdungxpt29-Sep-08 12:48 
GeneralVery good control Pin
Boogier26-Mar-08 0:19
memberBoogier26-Mar-08 0:19 
QuestionHow to Use It ? Pin
freddie200023-Nov-07 5:41
memberfreddie200023-Nov-07 5:41 
AnswerRe: How to Use It ? Pin
freddie200023-Nov-07 5:50
memberfreddie200023-Nov-07 5:50 
QuestionGreat Control, Can you modify it to add Range, Min and Max values it allows ? Pin
Vivek Krishnamurthy5-Sep-07 5:54
memberVivek Krishnamurthy5-Sep-07 5:54 
GeneralDrop Control on to form Pin
Neil Squires19-Jul-07 7:01
memberNeil Squires19-Jul-07 7:01 
AnswerRe: Drop Control on to form Pin
hellspawnfr1-Feb-08 22:28
memberhellspawnfr1-Feb-08 22:28 
GeneralRe: Drop Control on to form Pin
Mahmood Dehghan28-Mar-08 23:08
memberMahmood Dehghan28-Mar-08 23:08 
GeneralException Pin
naalexander27-Jul-06 3:12
membernaalexander27-Jul-06 3:12 

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

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

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