Tema: suma textbox
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/06/2011, 16:40
Avatar de bieres
bieres
 
Fecha de Ingreso: marzo-2011
Mensajes: 63
Antigüedad: 13 años, 1 mes
Puntos: 5
Respuesta: suma textbox

Perdona lo puse directamente y no cai en los valores nulos ("")
Código:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.textBox1.TextChanged += new EventHandler(textBox_TextChanged);
            this.textBox2.TextChanged += new EventHandler(textBox_TextChanged);
            this.textBox3.TextChanged += new EventHandler(textBox_TextChanged);
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            double x = 0;
            double y = 0;
            double z = 0;
            if (textBox1.Text != "")
            {
                x = Convert.ToDouble(textBox1.Text);
            }
            if (textBox2.Text != "")
            {
                y = Convert.ToDouble(textBox2.Text);
            }
            if (textBox3.Text != "")
            {
                z = Convert.ToDouble(textBox3.Text);
            }

            textBox4.Text = Convert.ToString(x + y + z);
        }
        
    }