Foros > C# (Sharp) ( Limpio y listo para usarse ): Como crear una Calculadora con C#

  1. malditosan

    Mensajes [3] - Enviado el Martes 24 de Marzo de 2009 a las 16:40hs

    Hola amigos me gustaria saber como crear una calculadora en c#, si pudiese estar comentada para poder ir visualizando la construccion seria ideal para los que estamos aprendiendo...

    :D

  2. thaNat0s

    Mensajes [8] - Enviado el Jueves 26 de Marzo de 2009 a las 00:54hs

    esta es una forma para crearla espero que te sirva como ejemplo
    namespace WindowsApplication1
    {
    public partial class Formcalculadora : Form
    {

    int operacion;
    string sPrimertermino, sSegundotermino;

    public Formcalculadora()
    {

    InitializeComponent();


    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void btnnum0_Click(object sender, EventArgs e)
    {

    string sNum0 = "0";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;

    }

    private void btnnum1_Click(object sender, EventArgs e)
    {
    string sNum0 = "1";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum2_Click(object sender, EventArgs e)
    {
    string sNum0 = "2";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum3_Click(object sender, EventArgs e)
    {
    string sNum0 = "3";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum4_Click(object sender, EventArgs e)
    {
    string sNum0 = "4";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum5_Click(object sender, EventArgs e)
    {
    string sNum0 = "5";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum6_Click(object sender, EventArgs e)
    {
    string sNum0 = "6";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum7_Click(object sender, EventArgs e)
    {
    string sNum0 = "7";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum8_Click(object sender, EventArgs e)
    {
    string sNum0 = "8";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnnum9_Click(object sender, EventArgs e)
    {
    string sNum0 = "9";
    sNum0 = txtoperaciones.Text + sNum0;
    txtoperaciones.Text = sNum0;
    }

    private void btnsuma_Click(object sender, EventArgs e)
    {

    operacion = 1;
    sPrimertermino = txtoperaciones.Text;
    txtoperaciones.Text = "";


    }


    private void btnresta_Click(object sender, EventArgs e)
    {
    operacion = 2;
    sPrimertermino = txtoperaciones.Text;
    txtoperaciones.Text = "";
    }

    private void btnmultiplicacion_Click(object sender, EventArgs e)
    {
    operacion = 3;
    sPrimertermino = txtoperaciones.Text;
    txtoperaciones.Text = "";
    }

    private void btndivision_Click(object sender, EventArgs e)
    {
    operacion = 4;
    sPrimertermino = txtoperaciones.Text;
    txtoperaciones.Text = "";
    }

    private void btnigual_Click(object sender, EventArgs e)
    {
    if (operacion == 1)
    {

    sSegundotermino = txtoperaciones.Text;
    int iPrimernumero = Convert.ToInt32(sPrimertermino);
    int iSegundonumero = Convert.ToInt32(sSegundotermino);
    int iResultado = Convert.ToInt32(txtoperaciones.Text);
    iResultado = iPrimernumero + iSegundonumero;
    string sResultado = Convert.ToString(iResultado);
    txtoperaciones.Text = sResultado;
    }

    if (operacion == 2)
    {

    sSegundotermino = txtoperaciones.Text;
    int iPrimernumero = Convert.ToInt32(sPrimertermino);
    int iSegundonumero = Convert.ToInt32(sSegundotermino);
    int iResultado = Convert.ToInt32(txtoperaciones.Text);
    iResultado = iPrimernumero - iSegundonumero;
    string sResultado = Convert.ToString(iResultado);
    txtoperaciones.Text = sResultado;
    }

    if (operacion == 3)
    {

    sSegundotermino = txtoperaciones.Text;
    int iPrimernumero = Convert.ToInt32(sPrimertermino);
    int iSegundonumero = Convert.ToInt32(sSegundotermino);
    int iResultado = Convert.ToInt32(txtoperaciones.Text);
    iResultado = iPrimernumero * iSegundonumero;
    string sResultado = Convert.ToString(iResultado);
    txtoperaciones.Text = sResultado;
    }

    if (operacion == 4)
    {

    sSegundotermino = txtoperaciones.Text;
    int iPrimernumero = Convert.ToInt32(sPrimertermino);
    int iSegundonumero = Convert.ToInt32(sSegundotermino);
    int iResultado = Convert.ToInt32(txtoperaciones.Text);
    iResultado = iPrimernumero / iSegundonumero;
    string sResultado = Convert.ToString(iResultado);
    txtoperaciones.Text = sResultado;
    }
    }

    private void btnborrar_Click(object sender, EventArgs e)
    {
    txtoperaciones.Text = "";
    }

    private void txtoperaciones_TextChanged(object sender, EventArgs e)
    {

    }
    }
    }
    esta es una calculadora en C#.NET 2005 que hace las operaciones basicas (suma resta multiplicacion y division) espero que te sirva


responder

Para poder responder a este tema tenes que ingresar. Si no tenes una cuenta podes registrarse gratis..

publicidad

API DE FACEBOOK
GOOGLE CALENDAR API
GOOGLE MAPS API