Click here to Skip to main content
15,501,351 members
Articles / Programming Languages / C#
Posted 25 Nov 2005


86 bookmarked

A Calculator Control Box

Rate me:
Please Sign up or sign in to vote.
4.22/5 (36 votes)
25 Nov 2005CPOL2 min read
A Calculator Control Box which can be used instead of a text box for numeric input.

Sample Image - CalculatorBox.jpg


Accepting input from the user is always a big challenge in software development. I faced many cases where the user needs to be controlled by the application to provide proper input. So, I designed some controls to provide that feature. But I felt there are some cases where the more than just controlling the input is required. For example, if user needs to input some amount, then the user might expect a calculator to do initial calculation for a particular field. In that case, the user uses his/her own preferred calculator to do the initial calculation. Some of them use their brain, some use a physical calculator, and some use the calculator available with Windows. All of these are out of the scope of the application that the user is using. So, I always felt the need to develop a calculator control, which will provide a very similar interface as the standard calculator found in the market. That was the motivation to develop this calculator box. This calculator box can be used instead of using a restricted text box control.


The CalculatorBox is a user control, which provides a specific feature to provide numerical input, especially for financial information. This control can be used as a text box control. It is more like a combo box control. It has two modes. One is the normal mode where the user can provide input for decimal numbers. Whenever the user wants to do some mathematical operations, the user can click on the arrow at the left, like in a combo box. It will display a calculator at the best possible place. The user can click on the calculator buttons, or use the keyboard to do the calculations. In text mode, if the user clicks any operation key (Add, Subtract, Multiply, or Divide), then it will automatically switch to calculator mode with the button pressed. If the calculator loses its focus, then automatically it will switch to text mode and the calculator will disappear.

Sample Image

If the user made some mistake in the calculation and wants a previous value, then the user can press the Esc button and the control will reset to the previous value.

This control has two properties: the Text property will provide whatever is available in the text box, and the Value property will provide the decimal value.

1.1 New Support

Culture Support

I use the current culture information from the CultureInfo class to decide the character for the the decimal point. The decimal point is used for display as well as to accept input from the user. For example, the Spanish language uses coma as a decimal separator. So, if the user sets the current culture as Spanish, then the calculator control will automatically use the coma as the decimal separator.

Culture Support


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) KAZ Software Limited
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionExcellent Pin
serkanyi3-Jan-17 1:21
Memberserkanyi3-Jan-17 1:21 
QuestionHow to add the Calculator box in c# textbox control Pin
avinasoni9-Oct-15 23:47
Memberavinasoni9-Oct-15 23:47 
GeneralMy vote of 5 Pin
Mardani Dani5-Jan-12 13:02
MemberMardani Dani5-Jan-12 13:02 
GeneralMy vote of 5 Pin
version_2.017-Jun-11 19:20
Memberversion_2.017-Jun-11 19:20 
GeneralMy vote of 4 Pin
Shinigamae7-Oct-10 3:49
MemberShinigamae7-Oct-10 3:49 
GeneralDecimal point not showing in decimal button in calculator. Pin
bodycode18-Aug-10 6:38
Memberbodycode18-Aug-10 6:38 
GeneralMy vote of 2 Pin
Whockie13-Oct-09 9:01
MemberWhockie13-Oct-09 9:01 
General[My vote of 2] questions Pin
fmzl14-Jun-09 23:27
Memberfmzl14-Jun-09 23:27 
Questioncan u help me? Pin
yasrebi30-May-08 0:37
Memberyasrebi30-May-08 0:37 
Generalhello can you help me Pin
wwfinz6-Jun-07 8:19
Memberwwfinz6-Jun-07 8:19 
QuestionWhat would be really cool.... Pin
M i s t e r L i s t e r4-May-07 11:55
MemberM i s t e r L i s t e r4-May-07 11:55 
QuestionHow to show it above all controls & form Pin
Anupam2128514-Jul-06 22:48
MemberAnupam2128514-Jul-06 22:48 
AnswerRe: How to show it above all controls & form Pin
H. S. Masud22-Sep-06 20:18
MemberH. S. Masud22-Sep-06 20:18 
AnswerRe: Calculator.CalculatorBox Pin
H. S. Masud25-Jun-06 0:27
MemberH. S. Masud25-Jun-06 0:27 
Generalproblem with calculator control box Pin
MonicaPaver3-May-06 7:33
MemberMonicaPaver3-May-06 7:33 
AnswerRe: problem with calculator control box Pin
H. S. Masud3-May-06 21:32
MemberH. S. Masud3-May-06 21:32 
GeneralGreat Idea Pin
M@dHatter22-Dec-05 9:49
MemberM@dHatter22-Dec-05 9:49 
JokeRe: Great Idea Pin
H. S. Masud24-Dec-05 5:29
MemberH. S. Masud24-Dec-05 5:29 
GeneralNice Control, but let me point out a little shortfall in culture support..... Pin
agapitar29-Nov-05 9:57
Memberagapitar29-Nov-05 9:57 
AnswerRe: Nice Control, but let me point out a little shortfall in culture support..... Pin
H. S. Masud29-Nov-05 20:46
MemberH. S. Masud29-Nov-05 20:46 
GeneralGreat Job Pin
Shahriar Hyder25-Nov-05 22:32
MemberShahriar Hyder25-Nov-05 22:32 
AnswerRe: Great Job Pin
H. S. Masud25-Nov-05 23:40
MemberH. S. Masud25-Nov-05 23:40 
GeneralRe: Great Job Pin
Shahriar Hyder26-Nov-05 18:54
MemberShahriar Hyder26-Nov-05 18:54 
QuestionExcellent Solution Pin
sulo2422-Feb-06 17:34
Membersulo2422-Feb-06 17:34 
AnswerRe: Excellent Solution Pin
H. S. Masud22-Feb-06 20:04
MemberH. S. Masud22-Feb-06 20:04 
Thanks for your comment. I'm not getting the problem you got. You can try by changing to width of the text box.


Hasan Shahriar Masud
Senior Software Engineer
Kaz Software limited
Dhaka, Bangladesh

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.