namespace Calculadora
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int longitud;
Double PrimerOperador, SegundoOperador, Resultado;
char operador;
private void Btn_7_Click(object sender, EventArgs e)
{
Button objetoBoton = (Button)sender;
Txt_Pantalla.Text += objetoBoton.Text;
}
private void Btn_division_Click(object sender, EventArgs e)
{
PrimerOperador = Convert.ToDouble(Txt_Pantalla.Text);
Button ObjOperacion = (Button)sender;
operador = Convert.ToChar(ObjOperacion.Text);
Txt_Pantalla.Clear();
}
private void Btn_igual_Click(object sender, EventArgs e)
{
SegundoOperador=Convert.ToDouble(Txt_Pantalla.Text);
switch (operador)
{
case '+':
Resultado = PrimerOperador + SegundoOperador;
break;
case '*':
Resultado = PrimerOperador * SegundoOperador;
break;
case '/':
Resultado = PrimerOperador / SegundoOperador;
break;
case '-':
Resultado = PrimerOperador - SegundoOperador;
break;
}
Txt_Pantalla.Text = PrimerOperador +" "+ operador + " "+ SegundoOperador;
Txt_PResultado.Text = Resultado.ToString();
}
private void Btn_Retroceso_Click(object sender, EventArgs e)
{
longitud = Txt_Pantalla.Text.Length;
Txt_Pantalla.Text = Txt_Pantalla.Text.Remove(longitud - 1, 1);
}
private void Btn_Limpiar_Click(object sender, EventArgs e)
{
Txt_Pantalla.Clear();
Txt_PResultado.Clear();
}
private void Btn_Memoria_Click(object sender, EventArgs e)
{
if (Txt_Pantalla.Text == "Me")
Btn_Memoria.Text = Btn_Memoria.ToString().Replace('.', ',');
}