sábado, 18 de octubre de 2014

Calculadora avanzada


}
        bool secuencia =true;
        string operacion;
        double num1, num2, resultado;
        //Numeros de la calculadora
        private void btnone_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "1";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "1";
            }
        }

             
        private void btntwo_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "2";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "2";
            }
        }

        private void btnthree_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
         {
                txtDisplay.Text = "";
                txtDisplay.Text = "3";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "3";
            }
        }

        private void btnfour_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "4";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "4";
            }
        }

        private void btnfive_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "5";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "5";
            }
        }

        private void btnsix_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "6";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "6";
            }
        }

        private void btnseven_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "7";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "7";
            }
        }

        private void btneight_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "8";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "8";
            }
        }

        private void btnnine_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = "9";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "9";
            }
        }

        private void btnzero_Click(object sender, EventArgs e)
        {
            if (txtDisplay.Text == "0")
            {
                return;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + "0";
            }
        }
        //Fin de los numeros de la calculadora
        //Inicio de los botones de operaciones
        private void btnpoint_Click(object sender, EventArgs e)
        {
            if (secuencia == true)
            {
                txtDisplay.Text = "";
                txtDisplay.Text = ".";
                secuencia = false;
            }
            else
            {
                txtDisplay.Text = txtDisplay.Text + ".";
            }
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            txtDisplay.Clear();
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void btnequals_Click(object sender, EventArgs e)
        {
            num2 = Double.Parse(txtDisplay.Text);
            if (operacion == "+")
            {
                resultado = num1 + num2;
                txtDisplay.Text = resultado.ToString();
                secuencia = true;
            }
            if (operacion == "-")
            {
                resultado = num1 - num2;
                txtDisplay.Text = resultado.ToString();
                secuencia = true;
            }
            if (operacion == "*")
            {
                resultado = num1 * num2;
                txtDisplay.Text = resultado.ToString();
                secuencia = true;
            }
            if (operacion == "/")
            {
                resultado = num1 / num2;
                txtDisplay.Text = resultado.ToString();
                secuencia = true;
            }

        }
        private void btnplus_Click(object sender, EventArgs e)
        {
            operacion = "+";
            num1 = double.Parse(txtDisplay.Text);
            secuencia = true;


        }
        private void btnminus_Click(object sender, EventArgs e)
        {
            operacion = "-";
            num1 = double.Parse(txtDisplay.Text);
            secuencia = true;

        }
        private void btnmultiplication_Click(object sender, EventArgs e)
        {
            operacion = "*";
            num1 = double.Parse(txtDisplay.Text);
            secuencia = true;

        }
        private void btndivision_Click(object sender, EventArgs e)
        {
            operacion = "/";
            num1 = double.Parse(txtDisplay.Text);
            secuencia = true;

        }
        private void btnporcentage_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(txtDisplay.Text);
            resultado = Math.Sqrt(num1 * num1);
            txtDisplay.Text = resultado.ToString();
            secuencia = true;

        }
        private void btnraiz_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(txtDisplay.Text);
            resultado = Math.Sqrt (num1);
            txtDisplay.Text = resultado.ToString();
            secuencia = true;
        }

        private void txtDisplay_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

No hay comentarios:

Publicar un comentario