按上图布局, 结果的事件: int i1, i2; if (int.TryParse(textBox1.Text, out i1) == false) { MessageBox.Show("第一个数含非法数字"); textBox1.Focus(); textBox1.BackColor = Color.Red; return; } if (int.TryParse(textBox2.Text, out i2) == false) { MessageBox.Show("第二个数含非法数字"); textBox2.Focus(); textBox2.BackColor = Color.Red; return; } textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Text = (i1 + i2).ToString(); /* int i1 = 0; int i2 = 0; try { i1 = Convert.ToInt32(textBox1.Text); } catch { MessageBox.Show("第一个数为非法的整数!"); label3.Text = "请重新输入第一个数"; textBox1.Focus(); textBox1.BackColor = Color.Red; return; } try { i2 = Convert.ToInt32(textBox2.Text); } catch { MessageBox.Show("第二个数为非法的数"); label3.Text = "请重新输入第二个数"; textBox2.Focus(); textBox2.BackColor = Color.Red; return; } int i3 = i1 + i2; textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Text = i3.ToString(); */