Friday, March 16, 2012

c# totals

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 WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private int value1 = 0;

private int value2 = 0;

private int value3 = 0;

private int value4 = 0;

private void textBox1_TextChanged(object sender, EventArgs e)

{

int i = 0;

if(int.TryParse(textBox1.Text, out i))

{

value1 = i;

DoIt();

}

else

{

textBox1.Text = value1.ToString();

}

}

private void textBox2_TextChanged(object sender, EventArgs e)

{

int i = 0;

if (int.TryParse(textBox2.Text, out i))

{

value2 = i;

DoIt();

}

else

{

textBox2.Text = value2.ToString();

}

}

private void textBox3_TextChanged(object sender, EventArgs e)

{

int i = 0;

if (int.TryParse(textBox3.Text, out i))

{

value3 = i;

DoIt();

}

else

{

textBox3.Text = value3.ToString();

}

}

private void textBox4_TextChanged(object sender, EventArgs e)

{

int i = 0;

if (int.TryParse(textBox4.Text, out i))

{

value4 = i;

DoIt();

}

else

{

textBox4.Text = value4.ToString();

}

}



private void DoIt()

{

textBox5.Text = (value1 + value2 + value3 + value4).ToString();

}





}

}