Saturday 25 February 2012

Simple Calculator on C#.net

Hii Guyzz To day am going to post a simple calculator code in c#.Net


ui of clculator





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;


namespace calci
{
    public partial class Form1 : Form
    {

        int a;
        int b;
        int c;

       
        public Form1()
        {
           
            InitializeComponent();
          
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        //clearing the output ie("c")
        private void button11_Click(object sender, EventArgs e) 
        {
            textBox1.Text = " ";
        }
       //getting the input to textbox by pressing the kyes.
        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "1";

        }
      
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "2";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "3";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "4";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "5";
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "6";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "7";
        }
        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "8";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "9";
        }

        private void button10_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + "0";
        }
       //now operators button code(i.e., +,-,*,etc)
       //here in every button we assigned a value to b according to that value the operations will be carried on.
        private void button12_Click(object sender, EventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);
            textBox1.Text = "";
            b = 1;
        }


        private void button13_Click(object sender, EventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);
            textBox1.Text = "";
            b = 2;
        }
       private void button14_Click(object sender, EventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);
            textBox1.Text = "";
            b = 4;
        }
       
       private void button15_Click(object sender, EventArgs e)
        {
            a = Convert.ToInt32(textBox1.Text);
            textBox1.Text = "";
            b = 3;
        }
        //this is the code for "=" button .
       private void button16_Click(object sender, EventArgs e)
        {


            switch (b)
            {
                case 1:
                    {
                        c = Convert.ToInt32(textBox1.Text);
                        c = c + a;
                        textBox1.Text = Convert.ToString(c);
                        break;
                   
                    }
                case 2:
                    {
                        c = Convert.ToInt32(textBox1.Text);
                        c = a - c;
                        textBox1.Text = Convert.ToString(c);
                        break;


                    }
                case 3:
                    {
                        c = Convert.ToInt32(textBox1.Text);
                        c = a * c;
                        textBox1.Text = Convert.ToString(c);
                        break;


                    }
                case 4:
                    {
                        c = Convert.ToInt32(textBox1.Text);
                        c = a / c;
                        textBox1.Text = Convert.ToString(c);
                        break;
                    }
            }
        }
}

No comments:

Post a Comment