Unidad 1. Actividad 2. Entregable. Calculadora Grafica Modificada PDF

Title Unidad 1. Actividad 2. Entregable. Calculadora Grafica Modificada
Course Programación 2
Institution Universidad del Caribe República Dominicana
Pages 14
File Size 302.6 KB
File Type PDF
Total Downloads 117
Total Views 136

Summary

Retomar el proyecto creado en la actividad 1 : calculadora grafica....


Description

CALCULADORA GRAFICA MODIFICADA

CAPTURAS PANTALLA DE LA CALCULADORA

CODIGO DE LA CALCULADORA

using using using using using using using using using

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

namespace calculadora_grafica { public enum Operacion { NoDefinida = 0, suma = 1, resta = 2, multiplicacion = 3, division = 4, porciento = 5, } public partial class Form1 : Form { double valor1 = 0; double valor2 = 0; Operacion operador = Operacion.NoDefinida; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button9_Click(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } private void button18_Click(object sender, EventArgs e) { } private void button7_Click(object sender, EventArgs e) { } private void leernumero (string numero) {

if (CAJARESULTADO.Text == "0" && CAJARESULTADO.Text != null) { CAJARESULTADO.Text = numero; } else { CAJARESULTADO.Text += numero; } } private double EjecutarOperacion() { double resultado = 0; switch (operador) { case Operacion.suma: resultado = valor1 + valor2; break; case Operacion.resta: resultado = valor1 - valor2; break; case Operacion.multiplicacion: resultado = valor1 * valor2; break; case Operacion.division: if (valor2 == 0) { MessageBox.Show("no se puede dividir entre 0"); resultado = 0; } else { resultado = valor1 / valor2; } break; case Operacion.porciento: resultado = valor1 % valor2; break; } return resultado; } private void btnCero_Click(object sender, EventArgs e) { if (CAJARESULTADO.Text == "0") { return; } else { CAJARESULTADO.Text += "0"; } } private void btnUno_Click(object sender, EventArgs e) { leernumero ("1"); } private void btnDos_Click(object sender, EventArgs e) {

leernumero("2"); } private void btnTres_Click(object sender, EventArgs e) { leernumero("3"); } private void btnCuatro_Click(object sender, EventArgs e) { leernumero("4"); } private void btnCinco_Click(object sender, EventArgs e) { leernumero("5"); } private void btnSeis_Click(object sender, EventArgs e) { leernumero("6"); } private void btnSiete_Click(object sender, EventArgs e) { leernumero("7"); } private void btnOcho_Click(object sender, EventArgs e) { leernumero("8"); } private void btnNueve_Click(object sender, EventArgs e) { leernumero("9"); } private void ObtenerValor (string operador) { valor1 = Convert.ToDouble(CAJARESULTADO.Text); HISTORIAL.Text = CAJARESULTADO.Text + operador; CAJARESULTADO.Text = "0"; } private void btnSuma_Click(object sender, EventArgs e) { operador = Operacion.suma; ObtenerValor("+"); } private void label1_Click(object sender, EventArgs e) { } private void btnResultado_Click(object sender, EventArgs e) { if (valor2 == 0) { valor2 = Convert.ToDouble(CAJARESULTADO.Text); HISTORIAL.Text += valor2 + "="; double resultado = EjecutarOperacion ();

valor1 = 0; valor2 = 0; CAJARESULTADO.Text = Convert.ToString(resultado); } } private void btnResta_Click(object sender, EventArgs e) { operador = Operacion.resta; ObtenerValor("-"); } private void btnMultiplicacion_Click(object sender, EventArgs e) { operador = Operacion.multiplicacion; ObtenerValor("*"); } private void btnDivision_Click(object sender, EventArgs e) { operador = Operacion.division; ObtenerValor("/"); } private void btnPorciento_Click(object sender, EventArgs e) { operador = Operacion.porciento; ObtenerValor("%"); } private void btnReset_Click(object sender, EventArgs e) { CAJARESULTADO.Text = "0"; HISTORIAL.Text = ""; } private void btnBorrar_Click(object sender, EventArgs e) { if (CAJARESULTADO.Text.Length > 1) { string txtResultado = CAJARESULTADO.Text; txtResultado = txtResultado.Substring(0, txtResultado.Length 1); if (txtResultado.Length == 1 && txtResultado.Contains ("-")) { CAJARESULTADO.Text = "0"; } else { CAJARESULTADO.Text = txtResultado; }

} else { CAJARESULTADO.Text = "0"; }

} private void btnPunto_Click(object sender, EventArgs e) { if (CAJARESULTADO.Text.Contains(".")) { return; } CAJARESULTADO.Text += "."; } } }

namespace calculadora_grafica { partial class Form1 { /// /// Variable del diseñador necesaria. /// private System.ComponentModel.IContainer components = null; /// /// Limpiar los recursos que se estén usando. /// /// true si los recursos administrados se deben desechar; false en caso contrario. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Código generado por el Diseñador de Windows Forms /// /// Método necesario para admitir el Diseñador. No se puede modificar /// el contenido de este método con el editor de código. /// private void InitializeComponent() { this.CAJARESULTADO = new System.Windows.Forms.TextBox(); this.btnUno = new System.Windows.Forms.Button(); this.btnTres = new System.Windows.Forms.Button(); this.btnDos = new System.Windows.Forms.Button(); this.btnCinco = new System.Windows.Forms.Button(); this.btnSeis = new System.Windows.Forms.Button(); this.btnCuatro = new System.Windows.Forms.Button(); this.btnOcho = new System.Windows.Forms.Button(); this.btnNueve = new System.Windows.Forms.Button(); this.btnSiete = new System.Windows.Forms.Button(); this.btnSuma = new System.Windows.Forms.Button();

this.btnResta = new System.Windows.Forms.Button(); this.btnMultiplicacion = new System.Windows.Forms.Button(); this.btnResultado = new System.Windows.Forms.Button(); this.btnPunto = new System.Windows.Forms.Button(); this.btnCero = new System.Windows.Forms.Button(); this.btnDivision = new System.Windows.Forms.Button(); this.btnPorciento = new System.Windows.Forms.Button(); this.btnReset = new System.Windows.Forms.Button(); this.btnBorrar = new System.Windows.Forms.Button(); this.HISTORIAL = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // CAJARESULTADO // this.CAJARESULTADO.BackColor = System.Drawing.SystemColors.Window; this.CAJARESULTADO.Font = new System.Drawing.Font("Microsoft Sans Serif", 30F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.CAJARESULTADO.Location = new System.Drawing.Point(41, 42); this.CAJARESULTADO.Multiline = true; this.CAJARESULTADO.Name = "CAJARESULTADO"; this.CAJARESULTADO.Size = new System.Drawing.Size(359, 57); this.CAJARESULTADO.TabIndex = 0; this.CAJARESULTADO.Text = "0"; this.CAJARESULTADO.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // btnUno // this.btnUno.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnUno.Location = new System.Drawing.Point(41, 353); this.btnUno.Name = "btnUno"; this.btnUno.Size = new System.Drawing.Size(70, 60); this.btnUno.TabIndex = 2; this.btnUno.Text = "1"; this.btnUno.UseVisualStyleBackColor = true; this.btnUno.Click += new System.EventHandler(this.btnUno_Click); // // btnTres // this.btnTres.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnTres.Location = new System.Drawing.Point(233, 353); this.btnTres.Name = "btnTres"; this.btnTres.Size = new System.Drawing.Size(70, 60); this.btnTres.TabIndex = 10; this.btnTres.Text = "3"; this.btnTres.UseVisualStyleBackColor = true; this.btnTres.Click += new System.EventHandler(this.btnTres_Click); // // btnDos // this.btnDos.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnDos.Location = new System.Drawing.Point(137, 353); this.btnDos.Name = "btnDos"; this.btnDos.Size = new System.Drawing.Size(70, 60);

this.btnDos.TabIndex = 11; this.btnDos.Text = "2"; this.btnDos.UseVisualStyleBackColor = true; this.btnDos.Click += new System.EventHandler(this.btnDos_Click); // // btnCinco // this.btnCinco.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnCinco.Location = new System.Drawing.Point(137, 263); this.btnCinco.Name = "btnCinco"; this.btnCinco.Size = new System.Drawing.Size(70, 60); this.btnCinco.TabIndex = 14; this.btnCinco.Text = "5"; this.btnCinco.UseVisualStyleBackColor = true; this.btnCinco.Click += new System.EventHandler(this.btnCinco_Click); // // btnSeis // this.btnSeis.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnSeis.Location = new System.Drawing.Point(233, 263); this.btnSeis.Name = "btnSeis"; this.btnSeis.Size = new System.Drawing.Size(70, 60); this.btnSeis.TabIndex = 13; this.btnSeis.Text = "6"; this.btnSeis.UseVisualStyleBackColor = true; this.btnSeis.Click += new System.EventHandler(this.btnSeis_Click); // // btnCuatro // this.btnCuatro.Font = new System.Drawing.Font("Arial Black", 16.2 F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnCuatro.Location = new System.Drawing.Point(41, 263); this.btnCuatro.Name = "btnCuatro"; this.btnCuatro.Size = new System.Drawing.Size(70, 60); this.btnCuatro.TabIndex = 12; this.btnCuatro.Text = "4"; this.btnCuatro.UseVisualStyleBackColor = true; this.btnCuatro.Click += new System.EventHandler(this.btnCuatro_Click); // // btnOcho // this.btnOcho.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnOcho.Location = new System.Drawing.Point(137, 175); this.btnOcho.Name = "btnOcho"; this.btnOcho.Size = new System.Drawing.Size(70, 60); this.btnOcho.TabIndex = 17; this.btnOcho.Text = "8"; this.btnOcho.UseVisualStyleBackColor = true; this.btnOcho.Click += new System.EventHandler(this.btnOcho_Click); // // btnNueve // this.btnNueve.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnNueve.Location = new System.Drawing.Point(233, 175); this.btnNueve.Name = "btnNueve"; this.btnNueve.Size = new System.Drawing.Size(70, 60); this.btnNueve.TabIndex = 16;

this.btnNueve.Text = "9"; this.btnNueve.UseVisualStyleBackColor = true; this.btnNueve.Click += new System.EventHandler(this.btnNueve_Click); // // btnSiete // this.btnSiete.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnSiete.Location = new System.Drawing.Point(41, 175); this.btnSiete.Name = "btnSiete"; this.btnSiete.Size = new System.Drawing.Size(70, 60); this.btnSiete.TabIndex = 15; this.btnSiete.Text = "7"; this.btnSiete.UseVisualStyleBackColor = true; this.btnSiete.Click += new System.EventHandler(this.btnSiete_Click); // // btnSuma // this.btnSuma.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnSuma.Location = new System.Drawing.Point(330, 343); this.btnSuma.Name = "btnSuma"; this.btnSuma.Size = new System.Drawing.Size(70, 60); this.btnSuma.TabIndex = 18; this.btnSuma.Text = "+"; this.btnSuma.UseVisualStyleBackColor = true; this.btnSuma.Click += new System.EventHandler(this.btnSuma_Click); // // btnResta // this.btnResta.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnResta.Location = new System.Drawing.Point(330, 258); this.btnResta.Name = "btnResta"; this.btnResta.Size = new System.Drawing.Size(70, 60); this.btnResta.TabIndex = 19; this.btnResta.Text = "-"; this.btnResta.UseVisualStyleBackColor = true; this.btnResta.Click += new System.EventHandler(this.btnResta_Click); // // btnMultiplicacion // this.btnMultiplicacion.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnMultiplicacion.Location = new System.Drawing.Point(330, 175); this.btnMultiplicacion.Name = "btnMultiplicacion"; this.btnMultiplicacion.Size = new System.Drawing.Size(70, 60); this.btnMultiplicacion.TabIndex = 20; this.btnMultiplicacion.Text = "X"; this.btnMultiplicacion.UseVisualStyleBackColor = true; this.btnMultiplicacion.Click += new System.EventHandler(this.btnMultiplicacion_Click); // // btnResultado // this.btnResultado.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnResultado.Location = new System.Drawing.Point(330, 436); this.btnResultado.Name = "btnResultado"; this.btnResultado.Size = new System.Drawing.Size(70, 60);

this.btnResultado.TabIndex = 21; this.btnResultado.Text = "="; this.btnResultado.UseVisualStyleBackColor = true; this.btnResultado.Click += new System.EventHandler(this.btnResultado_Click); // // btnPunto // this.btnPunto.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnPunto.Location = new System.Drawing.Point(235, 436); this.btnPunto.Name = "btnPunto"; this.btnPunto.Size = new System.Drawing.Size(70, 60); this.btnPunto.TabIndex = 22; this.btnPunto.Text = "."; this.btnPunto.UseVisualStyleBackColor = true; this.btnPunto.Click += new System.EventHandler(this.btnPunto_Click); // // btnCero // this.btnCero.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnCero.Location = new System.Drawing.Point(41, 436); this.btnCero.Name = "btnCero"; this.btnCero.Size = new System.Drawing.Size(166, 60); this.btnCero.TabIndex = 23; this.btnCero.Text = "0"; this.btnCero.UseVisualStyleBackColor = true; this.btnCero.Click += new System.EventHandler(this.btnCero_Click); // // btnDivision // this.btnDivision.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnDivision.Location = new System.Drawing.Point(330, 105); this.btnDivision.Name = "btnDivision"; this.btnDivision.Size = new System.Drawing.Size(70, 60); this.btnDivision.TabIndex = 24; this.btnDivision.Text = "/"; this.btnDivision.UseVisualStyleBackColor = true; this.btnDivision.Click += new System.EventHandler(this.btnDivision_Click); // // btnPorciento // this.btnPorciento.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnPorciento.Location = new System.Drawing.Point(233, 105); this.btnPorciento.Name = "btnPorciento"; this.btnPorciento.Size = new System.Drawing.Size(70, 60); this.btnPorciento.TabIndex = 25; this.btnPorciento.Text = "%"; this.btnPorciento.UseVisualStyleBackColor = true; this.btnPorciento.Click += new System.EventHandler(this.btnPorciento_Click); // // btnReset // this.btnReset.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnReset.Location = new System.Drawing.Point(41, 105);

this.btnReset.Name = "btnReset"; this.btnReset.Size = new System.Drawing.Size(70, 60); this.btnReset.TabIndex = 26; this.btnReset.Text = "C"; this.btnReset.UseVisualStyleBackColor = true; this.btnReset.Click += new System.EventHandler(this.btnReset_Click); // // btnBorrar // this.btnBorrar.Font = new System.Drawing.Font("Arial Black", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnBorrar.Location = new System.Drawing.Point(137, 105); this.btnBorrar.Name = "btnBorrar"; this.btnBorrar.Size = new System.Drawing.Size(70, 60); this.btnBorrar.TabIndex = 27; this.btnBorrar.Text = "...


Similar Free PDFs