ARTICLE

Just like windows calculator

Posted by Khaled Samir Articles | Visual C# November 16, 2007
A windows application to simulate windows standard calculator.
Reader Level:
Download Files:
 

Introduction

Most of us have used Windows Calculator before. In this article I have generated a Windows application to act as Microsoft Windows Standard Calculator.

The Program

The program is a Windows Forms application with Visual Studio 2005 C# language.

It contains just one class holds the interface of the application (the form) and also holds the business logic.

This class is named "MainForm".

The form consists of

  1. 10 numbers buttons (0-9) numbers.
  2. The memory handling buttons.
  3. The primitive operations buttons (plus, minus, multiply and division).
  4. Other operations buttons like Square root and etc..
  5. The Delete, C and CE buttons.
  6. The display Text Box.

Event Handling

Entering Numbers   

Entering numbers event handling is put in one method which displays each button number.

I made a small trick to make this function to work.

I named each button with the name "btn" and added the number after the text btn to let "btn9" is the name of the button that enters the number 9 to the screen.

Primitive Operations

I also made the event handling of all the basic operations in one method.

To do so, I made an enumeration to hold the current operation the user wants to do. It is addition, multiplication, division or subtraction.

The class holds the operation into a variable and then uses this information when it tries to calculate the final result.

Finally

I am trying to stop talking about the program and let you enjoy reading the code and try to calculate whatever you want.

Login to add your contents and source code to this article
post comment
     

thank you very much for making this calculator

Posted by mojahid islam Sep 13, 2010

i have tried lot of websites to create a calculator. Most of the coding contained errors. Buts yours is simply great without any error and working well.

Posted by prem kumar Aug 18, 2010

i had to do this as a mini project for my course in dot net .it really helped me a lot thanks

Posted by rajesh o Aug 06, 2010

I would like to thank .. Because u helped me to found a standered calculator like this.. thank you agian for your efforts :) 

Posted by Amr Adel Jul 20, 2010

i 'm really would like to thank you bashmohands Khaled because u helped me in my search for 2 day i was looking at a calculator like this. And finally i found but i have to confessed that the Calculator is not simple as i expected i have to understand alot of command here ...
<< Amr Adel >>

Posted by Amr Adel Jul 20, 2010
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.