public class Form1 : Form
{
private TextBox textBox1 = new TextBox();
private Form2 form2 = new Form2();
public Form1()
{
this.textBox1.Multiline = true;
this.textBox1.Height = 100;
this.textBox1.TextChanged += this.textBox1_TextChanged;
this.Controls.Add(this.textBox1);
this.Load += this.Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
form2.Show();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
int sum = 0;
foreach (string s in this.textBox1.Lines)
{
int v;
if (int.TryParse(s, out v))
{
sum += v;
}
}
form2.Sum = sum.ToString();
}
}
public class Form2 : Form
{
private TextBox textBox2 = new TextBox();
public Form2()
{
this.Controls.Add(this.textBox2);
}
public string Sum
{
set { this.textBox2.Text = value; }
}
}