Bienvenidos a un nuevo curso. Ahora estoy en el ciclo de grado superior: Desarrollo de aplicaciones multiplataforma. Y voy a ser parte del experimento de la formación dual. Estaré haciendo practicas durante un año, y a la vez finalizando la formación.

Deseadme suerte.

sábado, 5 de marzo de 2016

Calculadora 1

0









A Continuación os pongo el código completo. Como en las imágenes esta todo bien comentado y marcado. No veo que haga falta mayores explicaciones.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace calculadora_1
{
    public partial class Calculadora : Form
    {
        public Calculadora()
        {
            InitializeComponent();
        }
        //Creo el Boolenao, para disinguir operando 1, del 2 en el teclado.
        Boolean click;
        private void txtoperando1_Click(object sender, EventArgs e)
        {
            click = false;
        }

        private void txtOperando2_Click(object sender, EventArgs e)
        {
            click = true;
        }
        //Operandos
        int n1=0, n2=0;
        string operacion;
        //resultado
        private void txtresultado_TextChanged(object sender, EventArgs e)
        {
            txtresultado.ForeColor = Color.Red;
            switch (operacion)
            {
                case "+":
                    txtresultado.Text = (n1 + n2).ToString();
                    break;
                case "-":
                    txtresultado.Text = (n1 - n2).ToString();
                    break;
                case "*":
                    txtresultado.Text = (n1 * n2).ToString();
                    break;
                case "/":
                    txtresultado.Text = (n1 / n2).ToString();
                    break;
            }
        }
        //operando1
        private void txtoperando1_TextChanged(object sender, EventArgs e)
        {
            
        }
        //operando2
        private void txtOperando2_TextChanged(object sender, EventArgs e)
        {
            
        }
        //Teclado
        //Borrar
        private void btnBorrar_Click_1(object sender, EventArgs e)
        {
            txtoperando1.Text=" ";
            txtOperando2.Text=" ";
            txtresultado.Text=" ";
            n1 = 0;
            n2 = 0;
            operacion = "?";
            click = false;
        }
        //1
        private void btn1_Click(object sender, EventArgs e)
        {
            if (click==false)
            {
                txtoperando1.Text += 1;
            }
            else
            {
                txtOperando2.Text += 1;
            }
        }
        //2
        private void btn2_Click_1(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 2;
            }
            else
            {
                txtOperando2.Text += 2;
            }
        }
        //3
        private void btn3_Click_1(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 3;
            }
            else
            {
                txtOperando2.Text += 3;
            }
        }
        //4
        private void btn4_Click_1(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 4;
            }
            else
            {
                txtOperando2.Text += 4;
            }
        }
        //5
        private void btn5_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 5;
            }
            else
            {
                txtOperando2.Text += 5;
            }
        }
        //6
        private void btn6_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 6;
            }
            else
            {
                txtOperando2.Text += 6;
            }
        }
        //7
        private void btn7_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 7;
            }
            else
            {
                txtOperando2.Text += 7;
            }
        }
        //8
        private void btn8_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 8;
            }
            else
            {
                txtOperando2.Text += 8;
            }
        }
        //9
        private void btn9_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 9;
            }
            else
            {
                txtOperando2.Text += 9;
            }
        }
        //0
        private void button11_Click(object sender, EventArgs e)
        {
            if (click == false)
            {
                txtoperando1.Text += 0;
            }
            else
            {
                txtOperando2.Text += 0;
            }
        }
        //+
        private void btnSumar_Click(object sender, EventArgs e)
        {
            n1 = int.Parse(txtoperando1.Text);
            operacion = "+";
            click = true;
        }
        //-
        private void btnRestar_Click(object sender, EventArgs e)
        {
            n1 = int.Parse(txtoperando1.Text);
            operacion = "-";
            click = true;
        }
        //*
        private void btnMultiplicar_Click(object sender, EventArgs e)
        {
            n1 = int.Parse(txtoperando1.Text);
            operacion = "*";
            click = true;
        }
        //'/'
        private void btnDividir_Click(object sender, EventArgs e)
        {
            n1 = int.Parse(txtoperando1.Text);
            operacion = "/";
            click = true;
        }
        //=
        private void btnResultado_Click(object sender, EventArgs e)
        {
            n2 = int.Parse(txtOperando2.Text);
            txtresultado.Text = txtresultado.ToString();
        }
    }
}



0 comentarios:

Publicar un comentario

Etiquetas actuales

BD (67) DEF (64) PROG (64) SQL (44) Java (29) PRACTICAS (20) php (18) DI (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) HTML (13) SGE (12) ERP (9) CONSULTAS (8) css (8) Linux (5) XML (5) Android (4) PDM (4) C (3) NetBeans (3) PSP (3) SMARTY (3) comandos (3) HOOK (2) POST (2) XSD (2) cURL (2) JS (1) MEDIA-QUERYS (1) PDO (1) RESPONSIVE (1) TPL (1) TRADUCCIÓN (1) app_inventor (1)

Todas las etiquetas

EJER (78) BD (67) DEF (64) PROG (64) SQL (44) c# (40) Programación (39) Ficheros (36) Java (29) bases de datos (21) PRACTICAS (20) lenguajes de marcas (19) AD (18) Entorno de desarrollo (18) php (18) PROCEDIMIENTOS (17) DI (16) FORM (16) PRESTASHOP (16) PROGRAMACIÓN WEB (16) lenguaje C (16) E/R (14) HTML (13) SGE (12) Sistemas informáticos (10) ERP (9) CONSULTAS (8) TRANSACCIONES (8) TRIGGER (8) VISUAL BASIC (8) css (8) FUNCIONES (7) html5 (6) Ada (5) EXAMEN (5) Linux (5) XML (5) estructuras (5) Android (4) DISEÑO (4) INTERFAZ (4) LOG (4) OpenBravo (4) PDM (4) ACTUALIZAR (3) C (3) DIAGRAMA (3) Directorios (3) NEW (3) NOR (3) NetBeans (3) OLD (3) PSP (3) SMARTY (3) comandos (3) css3 (3) AISLAMIENTOS (2) C++ (2) CONTROLERRORES (2) ELIMINAR (2) HOOK (2) INSERTAR (2) INST (2) MULTITABLA (2) POST (2) RECURSIVIDAD (2) SUBCONSULTAS (2) VISTAS (2) XSD (2) cURL (2) punteros (2) AJENA (1) BLOQUEOS (1) Byte (1) CREACION (1) CRM (1) Configuración (1) Controles (1) Datos (1) GOTFOCUS (1) IMAGENES (1) INDICES (1) JS (1) Lenght (1) MEDIA-QUERYS (1) Mingw (1) MonoDeveloped (1) OPTIMISTA (1) PDO (1) PESIMISTA (1) RESPONSIVE (1) SPEAK (1) Scanner (1) Serializacion (1) Streams (1) System (1) TPL (1) TRADUCCIÓN (1) USUARIOS (1) UseSystemPasswordChar (1) app_inventor (1) char (1) examenes (1) libreoffice (1) make (1) redes (1)