اگر قصد دارید فقط عدد وارد بشه میتونید از کد زیر استفاده کنید
string OldValue1 = "0";
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == "")
textBox1.Text = "0";
try
{
textBox3.Text = (long.Parse(textBox1.Text) + long.Parse(textBox2.Text)).ToString();
textBox1.Text = long.Parse(textBox1.Text).ToString();
OldValue1 = textBox1.Text;
}
catch { textBox1.Text = OldValue1; }
textBox1.Select(textBox1.TextLength, 0);
}
string OldValue2 = "0";
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text == "")
textBox2.Text = "0";
try
{
textBox3.Text = (long.Parse(textBox1.Text) + long.Parse(textBox2.Text)).ToString();
textBox2.Text = long.Parse(textBox2.Text).ToString();
OldValue2 = textBox2.Text;
}
catch { textBox2.Text = OldValue2; }
textBox2.Select(textBox2.TextLength, 0);
}