Tuesday, April 1, 2014

How to Create a Calculator Using C# with asp.net visual studio .


Here i made a calculator for beginners . The beginners must  follow the codes . but not do copy and paste . at first you must understand that and then you can try to build your own codes . One thing is mind did when you will build your own logic then you can do anything . So try and gain success. By Syed maftahur Rahman Sohel .

The Graphical Interface :

The Code :

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 calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnone_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnone.Text;
        }

        private void btntwo_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btntwo.Text;
        }

        private void btnthree_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnthree.Text;
        }

        private void btnfour_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnfour.Text;
        }

        private void btnfive_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnfive.Text;
        }

        private void btnSix_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnSix.Text;
        }

        private void btnSeven_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnSeven.Text;
        }

        private void btnEight_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnEight.Text;
        }

        private void btnNine_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnNine.Text;
        }

        private void btnZero_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnZero.Text;
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            textDisplay.Clear();
        }
        double total1 = 0.0;
        bool plusButtonClicked = false;
        bool minusButtonClicked = false;
        bool mulButtonClicked = false;
        bool divButtonClicked = false;
       
        private void btnPlus_Click(object sender, EventArgs e)
        {
            total1 = (double)total1 + double.Parse(textDisplay.Text);
            textDisplay.Clear();
            plusButtonClicked = true;
            minusButtonClicked = false;
            mulButtonClicked = false;
            divButtonClicked = false;
        }
        double total2 = 0;
        private void btnEqual_Click(object sender, EventArgs e)
        {
            if (plusButtonClicked == true)
            {
                total2 = (double)total1 + double.Parse(textDisplay.Text);
            }
            else if (minusButtonClicked == true)
            {
                total2 = (double)total1 - double.Parse(textDisplay.Text);
            }
            else if (mulButtonClicked == true)
            {
                total2 = (double)total1 * double.Parse(textDisplay.Text);
            }
            else if (divButtonClicked == true)
            {
                total2 = (double)total1 / double.Parse(textDisplay.Text);
            }
            textDisplay.Text = total2.ToString();
            total1 = 0;
        }

        private void btnPoint_Click(object sender, EventArgs e)
        {
            textDisplay.Text = textDisplay.Text + btnPoint.Text;
        }

        private void btnMinus_Click(object sender, EventArgs e)
        {
            total1 = (double)total1 + double.Parse(textDisplay.Text);
            textDisplay.Clear();
           
            minusButtonClicked = true;
            plusButtonClicked = false;
            mulButtonClicked = false;
            divButtonClicked = false;

        }

        private void btnMul_Click(object sender, EventArgs e)
        {
            total1=(double)total1+double.Parse(textDisplay.Text);
            textDisplay.Clear();
            mulButtonClicked = true;
            minusButtonClicked = false;
            plusButtonClicked = false;
           
            divButtonClicked = false;

        }

        private void btnDivide_Click(object sender, EventArgs e)
        {
            total1 = (double)total1 + double.Parse(textDisplay.Text);
            textDisplay.Clear();
            divButtonClicked = true;
            mulButtonClicked = false;
            minusButtonClicked = false;
            plusButtonClicked = false;

        }
    }
}



2 comments: