Código
namespace WindowsFormsApplication2 { public partial class Calculadora : Form { bool initial = true; string operacion; Double Resultado; Double numero1; Double numero2; public Calculadora() { InitializeComponent(); } private void GlobalClick(object sender, EventArgs e) { // Convertir objeto sender en un button Button bt = (Button)sender; // Si es una operacion que inicia se quita el cero if (initial) txtpantalla.Text = ""; // Escribir el numero seleccionado en el TextBox txtpantalla.Text += bt.Text.ToString().Trim(); // Desabilitar la funcion initial initial = false; } private void cmdRetroceso_Click(object sender, EventArgs e) { // Si solo hay un valor entonces el retroseso manda al valor inicial cero if (txtpantalla.Text.Trim().Length == 1) { txtpantalla.Text = "0"; initial = true; } else { // Se elimina el ultimo numero en el campo de txtpantalla // 123 usando SubString solo cojo 12 txtpantalla.Text = txtpantalla.Text.Trim().Substring(0, txtpantalla.Text.Trim().Length - 1); } } private void cmdC_Click(object sender, EventArgs e) { txtpantalla.Text = "0"; initial = true; } // Botones de operaciones matematicas private void cmdsuma_Click(object sender, EventArgs e) { operacion = "+"; initial = true; numero1 = double.Parse(txtpantalla.Text); } private void cmdresta_Click(object sender, EventArgs e) { operacion = "-"; initial = true; numero1 = double.Parse(txtpantalla.Text); } private void cmdmulti_Click(object sender, EventArgs e) { operacion = "*"; initial = true; numero1 = double.Parse(txtpantalla.Text); } private void cmddividir_Click(object sender, EventArgs e) { operacion = "/"; initial = true; numero1 = double.Parse(txtpantalla.Text); } private void cmdigual_Click(object sender, EventArgs e) { numero2 = double.Parse(txtpantalla.Text); initial = true; switch (operacion) { case "+": Resultado = numero1 + numero2; txtpantalla.Text = Resultado.ToString(); break; case "-": Resultado = numero1 - numero2; txtpantalla.Text = Resultado.ToString(); break; case "*": Resultado = numero1 * numero2; txtpantalla.Text = Resultado.ToString(); break; case "/": Resultado = numero1 / numero2; txtpantalla.Text = Resultado.ToString(); break; //me falta el % } } } }
esto es lo que tengo hasta el momento espera sus comentarios