Calculator

Unknown | 2:23 AM |



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;

namespace WindowsFormsApplication1
{
    public partial class calculator : Form
    {
        public calculator()
        {
            InitializeComponent();
        }
        string var1, var2, op;

        private void btn1_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text+((Button)sender).Text;

        }

        private void btn2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text+((Button)sender).Text;
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn5_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn6_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn7_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn8_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn9_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btn0_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox1.Text + ((Button)sender).Text;
        }

        private void btnplus_Click(object sender, EventArgs e)
        {
            var1 = textBox1.Text;
            op = "+";
            textBox1.Text = "";
        }

        private void btnminus_Click(object sender, EventArgs e)
        {
            var1 = textBox1.Text;
            op = "-";
            textBox1.Text = "";
        }

        private void btnmul_Click(object sender, EventArgs e)
        {
            var1 = textBox1.Text;
            op = "*";
            textBox1.Text = "";
        }

        private void btndiv_Click(object sender, EventArgs e)
        {
            var1 = textBox1.Text;
            op = "/";
            textBox1.Text = "";
        }

        private void btnequal_Click(object sender, EventArgs e)
        {
            var2 = textBox1.Text;
            if (op == "+")
            {
                textBox1.Text = Convert.ToString(decimal.Parse(var1) + decimal.Parse(var2));
            }
            if (op == "-")
            {
                textBox1.Text = Convert.ToString(decimal.Parse(var1) - decimal.Parse(var2));
            }
            if (op == "*")
            {
                textBox1.Text = Convert.ToString(decimal.Parse(var1) * decimal.Parse(var2));
            }
            if (op == "/")
            {
                textBox1.Text = Convert.ToString(decimal.Parse(var1) / decimal.Parse(var2));
            }
        }

        private void btnac_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            var1 = "0";
            var2 = "0";
        }
    }
}

Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....