private void btnAdd_Click(object sender, EventArgs e)
{ Double s1 = 0, s2 = 0, result = 0; if (txtNumber1.Text != "") { try { s1 = Convert.ToDouble(txtNumber1.Text.ToString().Trim()); } catch { MessageBox.Show("请输入正确的数字!", "提示"); return; } } if (txtNumber2.Text != "") { try { s2 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("请输入正确的数字!", "提示"); return; } } result = s1 + s2; txtNumber3.Text = result.ToString(); } private void btnSub_Click(object sender, EventArgs e) { Double s1 = 0, s2 = 0, result = 0; if (txtNumber1.Text != "") { try { s1 = Convert.ToDouble(txtNumber1.Text.ToString().Trim()); } catch { MessageBox.Show("请输入正确的数字!", "提示"); return; } } if (txtNumber2.Text != "") { try { s2 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("请输入正确的数字!", "提示"); return; } } result = s1 - s2; txtNumber3.Text = result.ToString(); } private void btnMul_Click(object sender, EventArgs e) { Double s1 = 0, s2 = 0, result = 0; if (txtNumber1.Text != "") { try { s1 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("输入有误,请重新输入", "提示"); return; } } if (txtNumber2.Text != "") { try { s1 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("输入有误,请重新输入", "提示"); return; } } result = s1 * s2; txtNumber3.Text = result.ToString(); } private void btnDiv_Click(object sender, EventArgs e) { Double s1 = 0, s2 = 0, result = 0; if (txtNumber1.Text != "") { try { s1 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("输入有误,请重新输入","提示"); return; } } if (txtNumber2.Text != "") { try { s1 = Convert.ToDouble(txtNumber2.Text.ToString().Trim()); } catch { MessageBox.Show("输入有误,请重新输入", "提示"); return; } } if (s2 == 0.0) { MessageBox.Show("被除数不能为0!", "提示"); return; } result = s1 / s2; txtNumber3.Text = result.ToString(); }!(https://img-blog.csdnimg.cn/20200224180450293.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MjYxMTEx,size_16,color_FFFFFF,t_70)
简单计算器
最新推荐文章于 2023-09-18 09:54:05 发布