You are on page 1of 5

DISE�O:

namespace WindowsFormsApplication2
{
partial class frmSwitch
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed;
otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblnumero1 = new System.Windows.Forms.Label();
this.lbloperador = new System.Windows.Forms.Label();
this.lblnumero2 = new System.Windows.Forms.Label();
this.lblresultado = new System.Windows.Forms.Label();
this.txtnumero1 = new System.Windows.Forms.TextBox();
this.txtoperador = new System.Windows.Forms.TextBox();
this.txtnumero2 = new System.Windows.Forms.TextBox();
this.txtresultado = new System.Windows.Forms.TextBox();
this.btnOperar = new System.Windows.Forms.Button();
this.btnprueba = new System.Windows.Forms.Button();
this.btnfunciones = new System.Windows.Forms.Button();
this.btnlimpiar = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblnumero1
//
this.lblnumero1.AutoSize = true;
this.lblnumero1.Location = new System.Drawing.Point(12, 33);
this.lblnumero1.Name = "lblnumero1";
this.lblnumero1.Size = new System.Drawing.Size(53, 13);
this.lblnumero1.TabIndex = 0;
this.lblnumero1.Text = "N�mero 1";
//
// lbloperador
//
this.lbloperador.AutoSize = true;
this.lbloperador.Location = new System.Drawing.Point(117, 33);
this.lbloperador.Name = "lbloperador";
this.lbloperador.Size = new System.Drawing.Size(51, 13);
this.lbloperador.TabIndex = 1;
this.lbloperador.Text = "Operador";
//
// lblnumero2
//
this.lblnumero2.AutoSize = true;
this.lblnumero2.Location = new System.Drawing.Point(203, 33);
this.lblnumero2.Name = "lblnumero2";
this.lblnumero2.Size = new System.Drawing.Size(53, 13);
this.lblnumero2.TabIndex = 2;
this.lblnumero2.Text = "N�mero 2";
//
// lblresultado
//
this.lblresultado.AutoSize = true;
this.lblresultado.Location = new System.Drawing.Point(313, 33);
this.lblresultado.Name = "lblresultado";
this.lblresultado.Size = new System.Drawing.Size(55, 13);
this.lblresultado.TabIndex = 3;
this.lblresultado.Text = "Resultado";
//
// txtnumero1
//
this.txtnumero1.Location = new System.Drawing.Point(12, 59);
this.txtnumero1.Name = "txtnumero1";
this.txtnumero1.Size = new System.Drawing.Size(80, 20);
this.txtnumero1.TabIndex = 4;
//
// txtoperador
//
this.txtoperador.Location = new System.Drawing.Point(120, 59);
this.txtoperador.MaxLength = 1;
this.txtoperador.Name = "txtoperador";
this.txtoperador.Size = new System.Drawing.Size(48, 20);
this.txtoperador.TabIndex = 5;
//
// txtnumero2
//
this.txtnumero2.Location = new System.Drawing.Point(206, 59);
this.txtnumero2.Name = "txtnumero2";
this.txtnumero2.Size = new System.Drawing.Size(80, 20);
this.txtnumero2.TabIndex = 6;
//
// txtresultado
//
this.txtresultado.BackColor =
System.Drawing.SystemColors.ButtonHighlight;
this.txtresultado.Location = new System.Drawing.Point(316, 59);
this.txtresultado.Name = "txtresultado";
this.txtresultado.ReadOnly = true;
this.txtresultado.Size = new System.Drawing.Size(80, 20);
this.txtresultado.TabIndex = 7;
//
// btnOperar
//
this.btnOperar.Location = new System.Drawing.Point(26, 143);
this.btnOperar.Name = "btnOperar";
this.btnOperar.Size = new System.Drawing.Size(65, 23);
this.btnOperar.TabIndex = 8;
this.btnOperar.Text = "Operar";
this.btnOperar.UseVisualStyleBackColor = true;
this.btnOperar.Click += new System.EventHandler(this.btnOperar_Click);
//
// btnprueba
//
this.btnprueba.Location = new System.Drawing.Point(174, 143);
this.btnprueba.Name = "btnprueba";
this.btnprueba.Size = new System.Drawing.Size(65, 23);
this.btnprueba.TabIndex = 9;
this.btnprueba.Text = "Prueba";
this.btnprueba.UseVisualStyleBackColor = true;
//
// btnfunciones
//
this.btnfunciones.Location = new System.Drawing.Point(316, 143);
this.btnfunciones.Name = "btnfunciones";
this.btnfunciones.Size = new System.Drawing.Size(65, 23);
this.btnfunciones.TabIndex = 10;
this.btnfunciones.Text = "Funciones";
this.btnfunciones.UseVisualStyleBackColor = true;
//
// btnlimpiar
//
this.btnlimpiar.Location = new System.Drawing.Point(174, 225);
this.btnlimpiar.Name = "btnlimpiar";
this.btnlimpiar.Size = new System.Drawing.Size(65, 23);
this.btnlimpiar.TabIndex = 11;
this.btnlimpiar.Text = "Limpiar";
this.btnlimpiar.UseVisualStyleBackColor = true;
//
// frmSwitch
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(428, 324);
this.Controls.Add(this.btnlimpiar);
this.Controls.Add(this.btnfunciones);
this.Controls.Add(this.btnprueba);
this.Controls.Add(this.btnOperar);
this.Controls.Add(this.txtresultado);
this.Controls.Add(this.txtnumero2);
this.Controls.Add(this.txtoperador);
this.Controls.Add(this.txtnumero1);
this.Controls.Add(this.lblresultado);
this.Controls.Add(this.lblnumero2);
this.Controls.Add(this.lbloperador);
this.Controls.Add(this.lblnumero1);
this.Name = "frmSwitch";
this.Text = "frmSwitch";
this.ResumeLayout(false);
this.PerformLayout();

#endregion
private System.Windows.Forms.Label lblnumero1;
private System.Windows.Forms.Label lbloperador;
private System.Windows.Forms.Label lblnumero2;
private System.Windows.Forms.Label lblresultado;
private System.Windows.Forms.TextBox txtnumero1;
private System.Windows.Forms.TextBox txtoperador;
private System.Windows.Forms.TextBox txtnumero2;
private System.Windows.Forms.TextBox txtresultado;
private System.Windows.Forms.Button btnOperar;
private System.Windows.Forms.Button btnprueba;
private System.Windows.Forms.Button btnfunciones;
private System.Windows.Forms.Button btnlimpiar;
}
}

CODIGO:

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

namespace WindowsFormsApplication2
{
public partial class frmSwitch : Form
{
public frmSwitch()
{
InitializeComponent();
}

private void btnOperar_Click(object sender, EventArgs e)


{
#region variables
char operador;
double num1;
double num2;
double res;
#endregion

#region controles
if (double.TryParse(txtnumero1.Text, out num1) == false)
{
MessageBox.Show("Ingrese solo numeros en numero 1");

}
if (char.TryParse(txtoperador.Text, out operador) == false)
{
MessageBox.Show("Ingrese un operador +,-,/,*");

}
if
(double.TryParse(txtnumero2.Text, out num2) == false)
{
MessageBox.Show("Ingrese solo numeros en numero 2");
}
#endregion

#region Calculo
switch (operador)
{
case '+':
res = num1 + num2;
txtresultado.Text = res.ToString();
break;

case '-':
res = num1 - num2;
txtresultado.Text = res.ToString();
break;
case '*':
res = num1 * num2;
txtresultado.Text = res.ToString();
break;

case '/':
res = num1 / num2;
txtresultado.Text = res.ToString();
break;

default:
MessageBox.Show("No ingres� ning�n operador valido");
break;
}
#endregion

You might also like