Calculator!

All tutorials created in C# to be posted in here.
1 post Page 1 of 1
Contributors
User avatar
benji_19994
VIP - Donator
VIP - Donator
Posts: 156
Joined: Mon Apr 16, 2012 3:13 pm

Calculator!
benji_19994
Hey all this is my first Tutorial cooll; cooll; cooll; so here i go :)

Add 17 Button
name them
btnZero
btnOne
btnTwo
btnThree
btnFour
btnFive
btnSix
btnSeven
btnEight
btnNine

Size is:177, 175
and also add 1 textbox
you can line them up any way you like but i have ming like this
Image

now time for the code
Code: Select all
        private void btnOne_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnOne.Text;
        }

        private void btnTwo_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
        }

        private void btnThree_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnThree.Text;
        }

        private void btnFour_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnFour.Text;
        }

        private void btnFive_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnFive.Text;
        }

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

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

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

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

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

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtDisplay.Clear();
        }
        double total1 = 0;
        double total2 = 0;
        bool plusButtonClicked = true;
        bool minusButtonClicked = true;
        bool timesButtonClicked = true;
        bool DevideButtonClicked = true;
        private void btnPlus_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();
        }

        private void btnEquals_Click(object sender, EventArgs e)
        {
            if (plusButtonClicked == true)
            {
                total2 = total1 + double.Parse(txtDisplay.Text);
            }
            else if (minusButtonClicked == true)
            {
                total2 = total1 - double.Parse(txtDisplay.Text);
            }
            else if (DevideButtonClicked == true)
                total2 = total1 / double.Parse(txtDisplay.Text);
            
            else if (timesButtonClicked == true)
                total2 = total1 * double.Parse(txtDisplay.Text);
            {
           
                txtDisplay.Text = total2.ToString();
                total1 = 0;
            }
        }

        private void btnPiont_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = txtDisplay.Text + btnPiont.Text;
        }
       
        private void btnMinus_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();

            plusButtonClicked = false;
            minusButtonClicked = true;
            timesButtonClicked = false;
            DevideButtonClicked = false;
        }

        private void btnTimes_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();
            plusButtonClicked =false;
            minusButtonClicked = false;
            timesButtonClicked = true;
            DevideButtonClicked = false;
        }

        private void btnDivide_Click(object sender, EventArgs e)
        {
            total1 = total1 + double.Parse(txtDisplay.Text);
            txtDisplay.Clear();
            plusButtonClicked = false;
            minusButtonClicked = false;
            timesButtonClicked = false;
            DevideButtonClicked = true;
        }
    }
}
if you need any help just let me know
1 post Page 1 of 1
Return to “C-Sharp Tutorials”