Just like windows calculator


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.


Similar Articles