private void CalButton_Click(object sender, EventArgs e) { switch (sym) { case "+": ResultText.Text = $"{num_1 + num_2}"; break; case "-": ResultText.Text = $"{num_1 - num_2}"; break; case "*": ResultText.Text = $"{num_1 * num_2}"; break; case "/": { if (num_2 != 0) { ResultText.Text = $"{num_1 / num_2}"; break; } else { MessageBox.Show("除0错误"); Num2Text.Focus(); return; } } } }
private void Num2Text_TextChanged(object sender, EventArgs e) { if (Num2Text.Text.ToString() == "") { num_2 = 1; } else if (int.TryParse(Num2Text.Text.ToString(), out num_2)) { num_2 = int.Parse(Num2Text.Text.ToString()); } else { MessageBox.Show("输入有误"); Num2Text.Focus(); return; } }