Martes, Enero 3, 2012

Simple Calculator in C#


 

This is a simple calculator using c# language and windows form that allows user to perform the four mathematical operation. Follow the steps below:

1. Create a new Windows Form and name it Simple Calculator.

2. Put 15 Buttons and 1 Textbox.

3. Change the name of the buttons.  
  Label      Name
      0       zeroButton 
      1       oneButton 
      2       twoButton  
      3       threeButton 
      4       fourButton
      5       fiveButton
      6       sixButton
      7       sevenButton
      8       eightButton
      9       nineButton
      +      addButton
       -      subtractButton
       *      multiplyButton
       /      divideButton
       .      dotButton
      =      equalsButton
   CLR   clearButton

For the Textbox name it "outputTextbox" and make the alignment to the Right.

4. When your done in your design press F7 to go to the code editor.
5. Declare the following class variables.

6. Inside also the Form1 class, type this event handler to prevent repetition of codes.























7. Go back to the Designer View. In every number buttons (0-9), click the event at the properties and at the Click event choose your event handler for the number buttons.



















8. Next make the Calculate parameter. This will hold the code when we use the operation buttons.



























9. Make another event handler for the operation buttons. This code will allow the user in continuous calculations. Example: 1+2+3 = 6.















10. Go to the Designer View again and put the this event to the four operation buttons (+,-,*,/).





















11. Next, double click the equals button and type this code:














12. For the clear button type this code. This code will reset the value the user enter in the calculator.


















13. Lastly run your program and test your Simple Calculator.



 















Challenge:
       Make your own code for the dot button. This will sharpen your brain in the world of coding :))

3 komento:

  1. I have tried everything I could possibly think for the DOT BUTTON, pls help

    TumugonBurahin
  2. Yes your are wright and thanks for post a good topic . your post is

    top most in realated post of Welcome to my blog about making a simple calculator in C# language..

    TumugonBurahin
  3. nice info ,i will try this in my window Sakit.info

    TumugonBurahin